[PATCH] D42180: [NewGVN] Re-evaluate phi of ops if expr operands change.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 06:33:07 PST 2018


fhahn created this revision.
fhahn added reviewers: dberlin, davide, mcrosier.
Herald added a subscriber: Prazek.

If an operand of the expression gets moved to a different congruence
class, the expression could be evaluated differently, as the leader may
has changed.

Together with https://reviews.llvm.org/D42179 it fixes all failure cases from
https://bugs.llvm.org/show_bug.cgi?id=35074


Repository:
  rL LLVM

https://reviews.llvm.org/D42180

Files:
  lib/Transforms/Scalar/NewGVN.cpp
  test/Transforms/NewGVN/pr35074-phi-of-ops-expr-operand-change-cases-change.ll


Index: test/Transforms/NewGVN/pr35074-phi-of-ops-expr-operand-change-cases-change.ll
===================================================================
--- /dev/null
+++ test/Transforms/NewGVN/pr35074-phi-of-ops-expr-operand-change-cases-change.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -newgvn -S | FileCheck %s
+
+; CHECK-LABEL: WhileBody:
+; br i1 false, label %BoundsCheckFail275, label %BoundsCheckOk276
+; CHECK-LABEL: WhileEnd:
+
+define void @sort(i64 %.16) {
+Entry:
+  %0 = extractvalue { i64, i1 } undef, 0
+  %1 = lshr i64 %0, 2
+  br i1 undef, label %DivZeroFail2.i, label %WhileBody.lr.ph
+
+DivZeroFail2.i:                                   ; preds = %Entry
+  unreachable
+
+WhileBody.lr.ph:                                  ; preds = %Entry
+  %2 = udiv i64 %.16, %1
+  br label %WhileBody
+
+WhileBody:                                        ; preds = %BoundsCheckOk276, %WhileBody.lr.ph
+  %iterator = phi i64 [ 0, %WhileBody.lr.ph ], [ %6, %BoundsCheckOk276 ]
+  %3 = tail call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %iterator, i64 %2)
+  %4 = extractvalue { i64, i1 } %3, 0
+  %5 = tail call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %4, i64 1)
+  %6 = extractvalue { i64, i1 } %5, 0
+  %7 = icmp ugt i64 %iterator, %.16
+  br i1 %7, label %BoundsCheckFail275, label %BoundsCheckOk276
+
+WhileEnd:                                         ; preds = %BoundsCheckOk276
+  ret void
+
+BoundsCheckFail275:                               ; preds = %WhileBody
+  unreachable
+
+BoundsCheckOk276:                                 ; preds = %WhileBody
+  %8 = icmp ult i64 %6, %.16
+  br i1 %8, label %WhileBody, label %WhileEnd
+}
+
+declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i64)
Index: lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- lib/Transforms/Scalar/NewGVN.cpp
+++ lib/Transforms/Scalar/NewGVN.cpp
@@ -2686,6 +2686,11 @@
   auto *FoundVal = findPHIOfOpsLeader(E, OrigInst, PredBB);
   if (!FoundVal) {
     ExpressionToPhiOfOps[E].insert(OrigInst);
+    // Also force re-evaluation if any of the expressions operands change,
+    // as that could lead to a different result for the symbolic evaluation.
+    if (auto *BE = dyn_cast<BasicExpression>(E))
+      for (auto &Op : BE->operands())
+        ExpressionToPhiOfOps[createVariableOrConstant(Op)].insert(OrigInst);
     DEBUG(dbgs() << "Cannot find phi of ops operand for " << *TransInst
                  << " in block " << getBlockName(PredBB) << "\n");
     return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42180.130171.patch
Type: text/x-patch
Size: 2525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180117/eb5fd2a9/attachment.bin>


More information about the llvm-commits mailing list