[llvm] 1cd6b44 - [InstCombine] add one-use check to shift-shift transform

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 22 13:32:24 PDT 2021


Author: Sanjay Patel
Date: 2021-09-22T16:31:12-04:00
New Revision: 1cd6b44f267b256051e6106d9cf665f3bae2fd22

URL: https://github.com/llvm/llvm-project/commit/1cd6b44f267b256051e6106d9cf665f3bae2fd22
DIFF: https://github.com/llvm/llvm-project/commit/1cd6b44f267b256051e6106d9cf665f3bae2fd22.diff

LOG: [InstCombine] add one-use check to shift-shift transform

We don't want to create extra instructions, and this
could infinite loop with the proposed transform in D110170.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
    llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index b643cbac8fcc6..5d8dcc73ad747 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -702,7 +702,7 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
   Instruction *TrOp;
   const APInt *TrShiftAmt;
   if (I.isLogicalShift() && match(Op0, m_Trunc(m_Instruction(TrOp))) &&
-      match(TrOp, m_Shift(m_Value(), m_APInt(TrShiftAmt))) &&
+      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-amount-reassociation-with-truncation-shl.ll b/llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll
index 7b275ec42d334..798e5d6dc509d 100644
--- a/llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll
+++ b/llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll
@@ -266,9 +266,8 @@ define i16 @extra_use_on_first_shift(i32 %x) {
 ; CHECK-LABEL: @extra_use_on_first_shift(
 ; CHECK-NEXT:    [[A:%.*]] = ashr i32 [[X:%.*]], 3
 ; CHECK-NEXT:    call void @use32(i32 [[A]])
-; CHECK-NEXT:    [[SH1:%.*]] = lshr i32 [[A]], 6
-; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[SH1]] to i16
-; CHECK-NEXT:    [[SH:%.*]] = and i16 [[TMP1]], 1023
+; CHECK-NEXT:    [[TR:%.*]] = trunc i32 [[A]] to i16
+; CHECK-NEXT:    [[SH:%.*]] = lshr i16 [[TR]], 6
 ; CHECK-NEXT:    ret i16 [[SH]]
 ;
   %a = ashr i32 %x, 3


        


More information about the llvm-commits mailing list