summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2021-09-27 13:49:13 -0400
committerSanjay Patel <spatel@rotateright.com>2021-09-27 14:10:26 -0400
commit623f93ed1c99904a2b092c617bb392010e7a0184 (patch)
tree558446648b29bf4737ff6cb3f124c6e178267640
parentd992950078efd81971b8d84a862671b17af88bff (diff)
downloadllvm-623f93ed1c99904a2b092c617bb392010e7a0184.tar.gz
[InstCombine] add use check to shl transform
This bug was introduced with the refactoring in: 9075edc89bc9 ...but there were no tests to detect it.
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp2
-rw-r--r--llvm/test/Transforms/InstCombine/shift-shift.ll6
2 files changed, 3 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 950d2ab6bc9f..c59c21428c69 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 7c57cdf2f07f..163a39657343 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