[PATCH] D101772: [ValueTracking] soften assert for invertible recurrence matching

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 3 12:59:28 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG15a42339fe5f: [ValueTracking] soften assert for invertible recurrence matching (authored by spatel).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101772/new/

https://reviews.llvm.org/D101772

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Transforms/InstSimplify/icmp.ll


Index: llvm/test/Transforms/InstSimplify/icmp.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/icmp.ll
+++ llvm/test/Transforms/InstSimplify/icmp.ll
@@ -187,3 +187,29 @@
   %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
+}
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2608,7 +2608,8 @@
                                                   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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101772.342519.patch
Type: text/x-patch
Size: 1681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210503/826e8b43/attachment.bin>


More information about the llvm-commits mailing list