[llvm] 0c57a2e - [ValueTracking] Add support for `xor`/`disjoint or` in `getInvertibleOperands`
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 11:14:04 PDT 2024
Author: Noah Goldstein
Date: 2024-04-10T13:13:43-05:00
New Revision: 0c57a2e4b4e5a6e5dda78a313fc8d8e3c91797f5
URL: https://github.com/llvm/llvm-project/commit/0c57a2e4b4e5a6e5dda78a313fc8d8e3c91797f5
DIFF: https://github.com/llvm/llvm-project/commit/0c57a2e4b4e5a6e5dda78a313fc8d8e3c91797f5.diff
LOG: [ValueTracking] Add support for `xor`/`disjoint or` in `getInvertibleOperands`
This strengthens our `isKnownNonEqual` logic with some fairly
trivial cases.
Proofs: https://alive2.llvm.org/ce/z/4pxRTj
Closes #87705
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/icmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 9f16eaf9e09905..f3ea73b2f0ec4d 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3106,7 +3106,20 @@ getInvertibleOperands(const Operator *Op1,
switch (Op1->getOpcode()) {
default:
break;
- case Instruction::Add:
+ case Instruction::Or:
+ if (!cast<PossiblyDisjointInst>(Op1)->isDisjoint() ||
+ !cast<PossiblyDisjointInst>(Op2)->isDisjoint())
+ break;
+ [[fallthrough]];
+ case Instruction::Xor:
+ case Instruction::Add: {
+ Value *Other;
+ if (match(Op2, m_c_BinOp(m_Specific(Op1->getOperand(0)), m_Value(Other))))
+ return std::make_pair(Op1->getOperand(1), Other);
+ if (match(Op2, m_c_BinOp(m_Specific(Op1->getOperand(1)), m_Value(Other))))
+ return std::make_pair(Op1->getOperand(0), Other);
+ break;
+ }
case Instruction::Sub:
if (Op1->getOperand(0) == Op2->getOperand(0))
return getOperands(1);
diff --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll
index a66f7cb879ef9d..d1799098115496 100644
--- a/llvm/test/Transforms/InstSimplify/icmp.ll
+++ b/llvm/test/Transforms/InstSimplify/icmp.ll
@@ -281,14 +281,7 @@ define i1 @load_ptr_null_valid(ptr %p) null_pointer_is_valid {
define i1 @non_eq_disjoint_or_common_op(i8 %x, i8 %y, i8 %ww, i8 %a) {
; CHECK-LABEL: @non_eq_disjoint_or_common_op(
-; CHECK-NEXT: [[W:%.*]] = add nuw i8 [[WW:%.*]], 1
-; CHECK-NEXT: [[Z:%.*]] = add i8 [[Y:%.*]], [[W]]
-; CHECK-NEXT: [[XY:%.*]] = or disjoint i8 [[X:%.*]], [[Y]]
-; CHECK-NEXT: [[XZ:%.*]] = or disjoint i8 [[X]], [[Z]]
-; CHECK-NEXT: [[AXY:%.*]] = add i8 [[A:%.*]], [[XY]]
-; CHECK-NEXT: [[AXZ:%.*]] = add i8 [[A]], [[XZ]]
-; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AXY]], [[AXZ]]
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: ret i1 false
;
%w = add nuw i8 %ww, 1
%z = add i8 %y, %w
@@ -327,14 +320,7 @@ define i1 @non_eq_disjoint_or_common_op_fail(i8 %x, i8 %y, i8 %ww, i8 %a) {
define i1 @non_eq_xor_common_op(i8 %x, i8 %y, i8 %ww, i8 %a) {
; CHECK-LABEL: @non_eq_xor_common_op(
-; CHECK-NEXT: [[W:%.*]] = add nuw i8 [[WW:%.*]], 1
-; CHECK-NEXT: [[Z:%.*]] = add i8 [[Y:%.*]], [[W]]
-; CHECK-NEXT: [[XY:%.*]] = xor i8 [[Y]], [[X:%.*]]
-; CHECK-NEXT: [[XZ:%.*]] = xor i8 [[X]], [[Z]]
-; CHECK-NEXT: [[AXY:%.*]] = add i8 [[A:%.*]], [[XY]]
-; CHECK-NEXT: [[AXZ:%.*]] = add i8 [[A]], [[XZ]]
-; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AXY]], [[AXZ]]
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: ret i1 false
;
%w = add nuw i8 %ww, 1
%z = add i8 %y, %w
More information about the llvm-commits
mailing list