[llvm] c5d942a - [InstCombine] remove unnecessary one-use check from (C2 << X) << C1 fold

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon May 30 12:20:40 PDT 2022


Author: Sanjay Patel
Date: 2022-05-30T15:17:54-04:00
New Revision: c5d942a4fb21fba404ceb504ed087c297a1af7c3

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

LOG: [InstCombine] remove unnecessary one-use check from (C2 << X) << C1 fold

The restriction goes back to:
16f18ed7b555bce51
...but the fold only replaces a shift with a shift, so that's not necessary.
Generalizing to other opcodes is planned as a follow-up.

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 e5b0e32aa85e..8d5dbf83b7ea 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -1010,7 +1010,7 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
     Constant *C2;
     Value *X;
     // (C2 << X) << C1 --> (C2 << C1) << X
-    if (match(Op0, m_OneUse(m_Shl(m_Constant(C2), m_Value(X)))))
+    if (match(Op0, m_Shl(m_Constant(C2), m_Value(X))))
       return BinaryOperator::CreateShl(ConstantExpr::getShl(C2, C1), X);
 
     // (X * C2) << C1 --> X * (C2 << C1)

diff  --git a/llvm/test/Transforms/InstCombine/shift-shift.ll b/llvm/test/Transforms/InstCombine/shift-shift.ll
index f10b0381206f..d76f3c00261a 100644
--- a/llvm/test/Transforms/InstCombine/shift-shift.ll
+++ b/llvm/test/Transforms/InstCombine/shift-shift.ll
@@ -325,7 +325,7 @@ define i32 @shl_shl_constants_use(i32 %x) {
 ; CHECK-LABEL: @shl_shl_constants_use(
 ; CHECK-NEXT:    [[S:%.*]] = shl i32 -2013265920, [[X:%.*]]
 ; CHECK-NEXT:    call void @use32(i32 [[S]])
-; CHECK-NEXT:    [[R:%.*]] = shl i32 [[S]], 3
+; CHECK-NEXT:    [[R:%.*]] = shl i32 1073741824, [[X]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %s = shl i32 2281701376, %x ; 0x8800_0000


        


More information about the llvm-commits mailing list