[llvm] 6e8b17d - [InstCombine] Support or disjoint in displaced shift fold

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 06:00:49 PST 2023


Author: Nikita Popov
Date: 2023-12-07T15:00:40+01:00
New Revision: 6e8b17d8213e131ea49030672175c4c1a97f49e1

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

LOG: [InstCombine] Support or disjoint in displaced shift fold

When I originally added this fold, it did not actually fix my
motivation case, where the add was represented as an or. Now that
we have the disjoint flag this can finally be cleanly supported.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    llvm/test/Transforms/InstCombine/binop-of-displaced-shifts.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 39466a9e3751b..6002f599ca71a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2127,10 +2127,10 @@ Instruction *InstCombinerImpl::foldBinOpOfDisplacedShifts(BinaryOperator &I) {
   Constant *ShiftedC1, *ShiftedC2, *AddC;
   Type *Ty = I.getType();
   unsigned BitWidth = Ty->getScalarSizeInBits();
-  if (!match(&I,
-             m_c_BinOp(m_Shift(m_ImmConstant(ShiftedC1), m_Value(ShAmt)),
-                       m_Shift(m_ImmConstant(ShiftedC2),
-                               m_Add(m_Deferred(ShAmt), m_ImmConstant(AddC))))))
+  if (!match(&I, m_c_BinOp(m_Shift(m_ImmConstant(ShiftedC1), m_Value(ShAmt)),
+                           m_Shift(m_ImmConstant(ShiftedC2),
+                                   m_AddLike(m_Deferred(ShAmt),
+                                             m_ImmConstant(AddC))))))
     return nullptr;
 
   // Make sure the add constant is a valid shift amount.

diff  --git a/llvm/test/Transforms/InstCombine/binop-of-displaced-shifts.ll b/llvm/test/Transforms/InstCombine/binop-of-displaced-shifts.ll
index 07ed8f2908896..27a3c8743368a 100644
--- a/llvm/test/Transforms/InstCombine/binop-of-displaced-shifts.ll
+++ b/llvm/test/Transforms/InstCombine/binop-of-displaced-shifts.ll
@@ -332,10 +332,7 @@ define <2 x i8> @shl_or_non_splat_out_of_range(<2 x i8> %x) {
 define i8 @shl_or_with_or_disjoint_instead_of_add(i8 %x) {
 ; CHECK-LABEL: define i8 @shl_or_with_or_disjoint_instead_of_add
 ; CHECK-SAME: (i8 [[X:%.*]]) {
-; CHECK-NEXT:    [[SHIFT:%.*]] = shl i8 16, [[X]]
-; CHECK-NEXT:    [[ADD:%.*]] = or disjoint i8 [[X]], 1
-; CHECK-NEXT:    [[SHIFT2:%.*]] = shl i8 3, [[ADD]]
-; CHECK-NEXT:    [[BINOP:%.*]] = or i8 [[SHIFT]], [[SHIFT2]]
+; CHECK-NEXT:    [[BINOP:%.*]] = shl i8 22, [[X]]
 ; CHECK-NEXT:    ret i8 [[BINOP]]
 ;
   %shift = shl i8 16, %x


        


More information about the llvm-commits mailing list