[llvm] 15a4233 - [ValueTracking] soften assert for invertible recurrence matching
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon May 3 12:59:25 PDT 2021
Author: Sanjay Patel
Date: 2021-05-03T15:57:40-04:00
New Revision: 15a42339fe5f5daa86651e181df9a4f89d3ededf
URL: https://github.com/llvm/llvm-project/commit/15a42339fe5f5daa86651e181df9a4f89d3ededf
DIFF: https://github.com/llvm/llvm-project/commit/15a42339fe5f5daa86651e181df9a4f89d3ededf.diff
LOG: [ValueTracking] soften assert for invertible recurrence matching
There's a TODO comment in the code and discussion in D99912
about generalizing this, but I wasn't sure how to implement that,
so just going with a potential minimal fix to avoid crashing.
The test is a reduction beyond useful code (there's no user of
%user...), but it is based on https://llvm.org/PR50191, so this
is asserting on real code.
Differential Revision: https://reviews.llvm.org/D101772
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 f8daf6a01fa45..30c64f1cc4dcc 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2608,7 +2608,8 @@ static Optional<unsigned> getInvertibleOperand(const Operator *Op1,
cast<Operator>(BO2));
if (!Idx || *Idx != 0)
break;
- assert(BO1->getOperand(*Idx) == PN1 && BO2->getOperand(*Idx) == PN2);
+ if (BO1->getOperand(*Idx) != PN1 || BO2->getOperand(*Idx) != PN2)
+ break;
// Phi operands might not be in the same order. TODO: generalize
// interface to return pair of operands.
diff --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll
index 1d4e954256a0f..caa96b4b20856 100644
--- a/llvm/test/Transforms/InstSimplify/icmp.ll
+++ b/llvm/test/Transforms/InstSimplify/icmp.ll
@@ -187,3 +187,29 @@ define i1 @shl_div_cmp_greater(i8 %x) {
%cmp = icmp ule i8 %div, %x
ret i1 %cmp
}
+
+; Don't crash matching recurrences/invertible ops.
+
+define void @PR50191(i32 %x) {
+; CHECK-LABEL: @PR50191(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[P1:%.*]] = phi i32 [ [[X:%.*]], [[ENTRY:%.*]] ], [ [[SUB1:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[P2:%.*]] = phi i32 [ [[X]], [[ENTRY]] ], [ [[SUB2:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[SUB1]] = sub i32 [[P1]], [[P2]]
+; CHECK-NEXT: [[SUB2]] = sub i32 42, [[P2]]
+; CHECK-NEXT: br label [[LOOP]]
+;
+entry:
+ br label %loop
+
+loop:
+ %p1 = phi i32 [ %x, %entry ], [ %sub1, %loop ]
+ %p2 = phi i32 [ %x, %entry ], [ %sub2, %loop ]
+ %cmp = icmp eq i32 %p1, %p2
+ %user = zext i1 %cmp to i32
+ %sub1 = sub i32 %p1, %p2
+ %sub2 = sub i32 42, %p2
+ br label %loop
+}
More information about the llvm-commits
mailing list