[llvm] 64bba21 - [InstCombine] Propagate disjoint flags during shl-binop transform (#91333)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 26 16:46:41 PDT 2024
Author: AtariDreams
Date: 2024-05-26T19:46:37-04:00
New Revision: 64bba2178f4c3af821e1aee9c5b86b77e030dd70
URL: https://github.com/llvm/llvm-project/commit/64bba2178f4c3af821e1aee9c5b86b77e030dd70
DIFF: https://github.com/llvm/llvm-project/commit/64bba2178f4c3af821e1aee9c5b86b77e030dd70.diff
LOG: [InstCombine] Propagate disjoint flags during shl-binop transform (#91333)
Alive2 Proof:
https://alive2.llvm.org/ce/z/D2jHrn
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/test/Transforms/InstCombine/shl-bo.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 3b56172cf5645..4f91993750fd2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -1174,7 +1174,11 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
// X & (CC << C)
Value *M = Builder.CreateAnd(X, ConstantInt::get(Ty, CC->shl(*C)),
X->getName() + ".mask");
- return BinaryOperator::Create(Op0BO->getOpcode(), M, YS);
+ auto *NewOp = BinaryOperator::Create(Op0BO->getOpcode(), M, YS);
+ if (auto *Disjoint = dyn_cast<PossiblyDisjointInst>(Op0BO);
+ Disjoint && Disjoint->isDisjoint())
+ cast<PossiblyDisjointInst>(NewOp)->setIsDisjoint(true);
+ return NewOp;
}
}
diff --git a/llvm/test/Transforms/InstCombine/shl-bo.ll b/llvm/test/Transforms/InstCombine/shl-bo.ll
index d33d27c912d6b..ab6e8c28cf9fc 100644
--- a/llvm/test/Transforms/InstCombine/shl-bo.ll
+++ b/llvm/test/Transforms/InstCombine/shl-bo.ll
@@ -294,6 +294,39 @@ define i8 @lshr_and_or(i8 %a, i8 %y) {
ret i8 %l
}
+define i8 @lshr_and_or_disjoint(i8 %a, i8 %y) {
+; CHECK-LABEL: @lshr_and_or_disjoint(
+; CHECK-NEXT: [[X:%.*]] = srem i8 [[A:%.*]], 42
+; CHECK-NEXT: [[B1:%.*]] = shl i8 [[X]], 2
+; CHECK-NEXT: [[Y_MASK:%.*]] = and i8 [[Y:%.*]], 52
+; CHECK-NEXT: [[L:%.*]] = or disjoint i8 [[Y_MASK]], [[B1]]
+; CHECK-NEXT: ret i8 [[L]]
+;
+ %x = srem i8 %a, 42 ; thwart complexity-based canonicalization
+ %r = lshr i8 %y, 2
+ %m = and i8 %r, 13
+ %b = or disjoint i8 %x, %m
+ %l = shl i8 %b, 2
+ ret i8 %l
+}
+
+define i8 @ashr_and_or_disjoint(i8 %a, i8 %y) {
+; CHECK-LABEL: @ashr_and_or_disjoint(
+; CHECK-NEXT: [[X:%.*]] = srem i8 [[A:%.*]], 42
+; CHECK-NEXT: [[B1:%.*]] = shl i8 [[X]], 2
+; CHECK-NEXT: [[Y_MASK:%.*]] = and i8 [[Y:%.*]], 52
+; CHECK-NEXT: [[L:%.*]] = or disjoint i8 [[Y_MASK]], [[B1]]
+; CHECK-NEXT: ret i8 [[L]]
+;
+ %x = srem i8 %a, 42 ; thwart complexity-based canonicalization
+ %r = ashr i8 %y, 2
+ %m = and i8 %r, 13
+ %b = or disjoint i8 %x, %m
+ %l = shl i8 %b, 2
+ ret i8 %l
+}
+
+
define <2 x i8> @lshr_and_or_commute_splat(<2 x i8> %a, <2 x i8> %y) {
; CHECK-LABEL: @lshr_and_or_commute_splat(
; CHECK-NEXT: [[X:%.*]] = srem <2 x i8> [[A:%.*]], <i8 42, i8 42>
@@ -614,8 +647,8 @@ define <8 x i16> @test_FoldShiftByConstant_CreateSHL2(<8 x i16> %in) {
define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) {
; CHECK-LABEL: @test_FoldShiftByConstant_CreateAnd(
-; CHECK-NEXT: [[TMP1:%.*]] = mul <16 x i8> [[IN0:%.*]], <i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33>
-; CHECK-NEXT: [[VSHL_N:%.*]] = and <16 x i8> [[TMP1]], <i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32>
+; CHECK-NEXT: [[VSRA_N2:%.*]] = mul <16 x i8> [[IN0:%.*]], <i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33>
+; CHECK-NEXT: [[VSHL_N:%.*]] = and <16 x i8> [[VSRA_N2]], <i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32>
; CHECK-NEXT: ret <16 x i8> [[VSHL_N]]
;
%vsra_n = ashr <16 x i8> %in0, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5>
More information about the llvm-commits
mailing list