diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index 950d2ab6bc9fc..c59c21428c696 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -860,7 +860,7 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) { // we have confidence that the shifts will get folded together. Instruction *TrOp; const APInt *TrShiftAmt; - if (match(Op0, m_Trunc(m_Instruction(TrOp))) && + if (match(Op0, m_OneUse(m_Trunc(m_Instruction(TrOp)))) && match(TrOp, m_OneUse(m_Shift(m_Value(), m_APInt(TrShiftAmt)))) && TrShiftAmt->ult(TrOp->getType()->getScalarSizeInBits())) { Type *SrcTy = TrOp->getType(); diff --git a/llvm/test/Transforms/InstCombine/shift-shift.ll b/llvm/test/Transforms/InstCombine/shift-shift.ll index 7c57cdf2f07f5..163a396573438 100644 --- a/llvm/test/Transforms/InstCombine/shift-shift.ll +++ b/llvm/test/Transforms/InstCombine/shift-shift.ll @@ -198,8 +198,7 @@ define i8 @shl_trunc_bigger_lshr_use2(i32 %x) { ; CHECK-NEXT: [[RT:%.*]] = lshr i32 [[X:%.*]], 5 ; CHECK-NEXT: [[TR:%.*]] = trunc i32 [[RT]] to i8 ; CHECK-NEXT: call void @use8(i8 [[TR]]) -; CHECK-NEXT: [[LT1:%.*]] = shl nuw nsw i32 [[RT]], 3 -; CHECK-NEXT: [[LT:%.*]] = trunc i32 [[LT1]] to i8 +; CHECK-NEXT: [[LT:%.*]] = shl i8 [[TR]], 3 ; CHECK-NEXT: ret i8 [[LT]] ; %rt = lshr i32 %x, 5 @@ -214,8 +213,7 @@ define i8 @shl_trunc_smaller_lshr_use2(i32 %x) { ; CHECK-NEXT: [[RT:%.*]] = lshr i32 [[X:%.*]], 3 ; CHECK-NEXT: [[TR:%.*]] = trunc i32 [[RT]] to i8 ; CHECK-NEXT: call void @use8(i8 [[TR]]) -; CHECK-NEXT: [[LT1:%.*]] = shl i32 [[RT]], 5 -; CHECK-NEXT: [[LT:%.*]] = trunc i32 [[LT1]] to i8 +; CHECK-NEXT: [[LT:%.*]] = shl i8 [[TR]], 5 ; CHECK-NEXT: ret i8 [[LT]] ; %rt = lshr i32 %x, 3