Skip to content

Commit 0c57a2e

Browse files
committed
[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 llvm#87705
1 parent 195d278 commit 0c57a2e

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,20 @@ getInvertibleOperands(const Operator *Op1,
31063106
switch (Op1->getOpcode()) {
31073107
default:
31083108
break;
3109-
case Instruction::Add:
3109+
case Instruction::Or:
3110+
if (!cast<PossiblyDisjointInst>(Op1)->isDisjoint() ||
3111+
!cast<PossiblyDisjointInst>(Op2)->isDisjoint())
3112+
break;
3113+
[[fallthrough]];
3114+
case Instruction::Xor:
3115+
case Instruction::Add: {
3116+
Value *Other;
3117+
if (match(Op2, m_c_BinOp(m_Specific(Op1->getOperand(0)), m_Value(Other))))
3118+
return std::make_pair(Op1->getOperand(1), Other);
3119+
if (match(Op2, m_c_BinOp(m_Specific(Op1->getOperand(1)), m_Value(Other))))
3120+
return std::make_pair(Op1->getOperand(0), Other);
3121+
break;
3122+
}
31103123
case Instruction::Sub:
31113124
if (Op1->getOperand(0) == Op2->getOperand(0))
31123125
return getOperands(1);

llvm/test/Transforms/InstSimplify/icmp.ll

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,7 @@ define i1 @load_ptr_null_valid(ptr %p) null_pointer_is_valid {
281281

282282
define i1 @non_eq_disjoint_or_common_op(i8 %x, i8 %y, i8 %ww, i8 %a) {
283283
; CHECK-LABEL: @non_eq_disjoint_or_common_op(
284-
; CHECK-NEXT: [[W:%.*]] = add nuw i8 [[WW:%.*]], 1
285-
; CHECK-NEXT: [[Z:%.*]] = add i8 [[Y:%.*]], [[W]]
286-
; CHECK-NEXT: [[XY:%.*]] = or disjoint i8 [[X:%.*]], [[Y]]
287-
; CHECK-NEXT: [[XZ:%.*]] = or disjoint i8 [[X]], [[Z]]
288-
; CHECK-NEXT: [[AXY:%.*]] = add i8 [[A:%.*]], [[XY]]
289-
; CHECK-NEXT: [[AXZ:%.*]] = add i8 [[A]], [[XZ]]
290-
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AXY]], [[AXZ]]
291-
; CHECK-NEXT: ret i1 [[R]]
284+
; CHECK-NEXT: ret i1 false
292285
;
293286
%w = add nuw i8 %ww, 1
294287
%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) {
327320

328321
define i1 @non_eq_xor_common_op(i8 %x, i8 %y, i8 %ww, i8 %a) {
329322
; CHECK-LABEL: @non_eq_xor_common_op(
330-
; CHECK-NEXT: [[W:%.*]] = add nuw i8 [[WW:%.*]], 1
331-
; CHECK-NEXT: [[Z:%.*]] = add i8 [[Y:%.*]], [[W]]
332-
; CHECK-NEXT: [[XY:%.*]] = xor i8 [[Y]], [[X:%.*]]
333-
; CHECK-NEXT: [[XZ:%.*]] = xor i8 [[X]], [[Z]]
334-
; CHECK-NEXT: [[AXY:%.*]] = add i8 [[A:%.*]], [[XY]]
335-
; CHECK-NEXT: [[AXZ:%.*]] = add i8 [[A]], [[XZ]]
336-
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AXY]], [[AXZ]]
337-
; CHECK-NEXT: ret i1 [[R]]
323+
; CHECK-NEXT: ret i1 false
338324
;
339325
%w = add nuw i8 %ww, 1
340326
%z = add i8 %y, %w

0 commit comments

Comments
 (0)