[llvm] 623f93e - [InstCombine] add use check to shl transform

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 27 11:10:36 PDT 2021


Author: Sanjay Patel
Date: 2021-09-27T14:10:26-04:00
New Revision: 623f93ed1c99904a2b092c617bb392010e7a0184

URL: https://github.com/llvm/llvm-project/commit/623f93ed1c99904a2b092c617bb392010e7a0184
DIFF: https://github.com/llvm/llvm-project/commit/623f93ed1c99904a2b092c617bb392010e7a0184.diff

LOG: [InstCombine] add use check to shl transform

This bug was introduced with the refactoring in:
9075edc89bc9
...but there were no tests to detect it.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
    llvm/test/Transforms/InstCombine/shift-shift.ll

Removed: 
    


################################################################################
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


        


More information about the llvm-commits mailing list