[llvm] r298687 - NewGVN: Fix PR32403 - Handling of undef in phis was not quite correct
Daniel Berlin via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 23 22:30:35 PDT 2017
Author: dannyb
Date: Fri Mar 24 00:30:34 2017
New Revision: 298687
URL: http://llvm.org/viewvc/llvm-project?rev=298687&view=rev
Log:
NewGVN: Fix PR32403 - Handling of undef in phis was not quite correct
due to LLVM's view of phi nodes. It would cause NewGVN not to fixpoint
in some interesting edge cases.
Added:
llvm/trunk/test/Transforms/NewGVN/pr32403.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=298687&r1=298686&r2=298687&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Fri Mar 24 00:30:34 2017
@@ -368,6 +368,7 @@ private:
const Expression *performSymbolicPredicateInfoEvaluation(Instruction *);
// Congruence finding.
+ bool someEquivalentDominates(const Instruction *, const Instruction *) const;
Value *lookupOperandLeader(Value *) const;
void performCongruenceFinding(Instruction *, const Expression *);
void moveValueToNewCongruenceClass(Instruction *, CongruenceClass *,
@@ -724,6 +725,18 @@ const CallExpression *NewGVN::createCall
return E;
}
+// Return true if some equivalent of instruction Inst dominates instruction U.
+bool NewGVN::someEquivalentDominates(const Instruction *Inst,
+ const Instruction *U) const {
+ auto *CC = ValueToClass.lookup(Inst);
+ assert(isa<Instruction>(CC->RepLeader) && CC->RepLeader == Inst);
+ if (CC)
+ return llvm::any_of(CC->Members, [&](const Value *Member) {
+ return DT->dominates(cast<Instruction>(Member), U);
+ });
+ return false;
+}
+
// See if we have a congruence class and leader for this operand, and if so,
// return it. Otherwise, return the operand itself.
Value *NewGVN::lookupOperandLeader(Value *V) const {
@@ -1054,7 +1067,7 @@ const Expression *NewGVN::performSymboli
if (HasUndef) {
// Only have to check for instructions
if (auto *AllSameInst = dyn_cast<Instruction>(AllSameValue))
- if (!DT->dominates(AllSameInst, I))
+ if (!someEquivalentDominates(AllSameInst, I))
return E;
}
Added: llvm/trunk/test/Transforms/NewGVN/pr32403.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/NewGVN/pr32403.ll?rev=298687&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/NewGVN/pr32403.ll (added)
+++ llvm/trunk/test/Transforms/NewGVN/pr32403.ll Fri Mar 24 00:30:34 2017
@@ -0,0 +1,65 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+;RUN: opt -newgvn -S < %s | FileCheck %s
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.12.0"
+
+; Function Attrs: nounwind ssp uwtable
+define void @reorder_ref_pic_list() local_unnamed_addr {
+; CHECK-LABEL: @reorder_ref_pic_list(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 undef, label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
+; CHECK: for.body.preheader:
+; CHECK-NEXT: br label [[FOR_BODY:%.*]]
+; CHECK: for.body:
+; CHECK-NEXT: [[REFIDXLX_0:%.*]] = phi i32 [ [[INC_I51:%.*]], [[IF_ELSE58:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
+; CHECK-NEXT: br i1 undef, label [[IF_THEN13:%.*]], label [[IF_ELSE58]]
+; CHECK: if.then13:
+; CHECK-NEXT: [[INC_I:%.*]] = add nsw i32 [[REFIDXLX_0]], 1
+; CHECK-NEXT: br label [[FOR_BODY8_I:%.*]]
+; CHECK: for.body8.i:
+; CHECK-NEXT: br i1 undef, label [[FOR_INC24_I:%.*]], label [[IF_THEN17_I:%.*]]
+; CHECK: if.then17.i:
+; CHECK-NEXT: br label [[FOR_INC24_I]]
+; CHECK: for.inc24.i:
+; CHECK-NEXT: br label [[FOR_BODY8_I]]
+; CHECK: if.else58:
+; CHECK-NEXT: [[INC_I51]] = add nsw i32 [[REFIDXLX_0]], 1
+; CHECK-NEXT: br label [[FOR_BODY]]
+; CHECK: for.end:
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 undef, label %for.end, label %for.body.preheader
+
+for.body.preheader: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %if.else58, %for.body.preheader
+ %refIdxLX.0 = phi i32 [ %inc.i51, %if.else58 ], [ 0, %for.body.preheader ]
+ br i1 undef, label %if.then13, label %if.else58
+
+if.then13: ; preds = %for.body
+ %inc.i = add nsw i32 %refIdxLX.0, 1
+ br label %for.body8.i
+
+for.body8.i: ; preds = %for.inc24.i, %if.then13
+ %nIdx.052.i = phi i32 [ %inc.i, %if.then13 ], [ %nIdx.1.i, %for.inc24.i ]
+ br i1 undef, label %for.inc24.i, label %if.then17.i
+
+if.then17.i: ; preds = %for.body8.i
+ br label %for.inc24.i
+
+for.inc24.i: ; preds = %if.then17.i, %for.body8.i
+ %nIdx.1.i = phi i32 [ undef, %if.then17.i ], [ %nIdx.052.i, %for.body8.i ]
+ br label %for.body8.i
+
+if.else58: ; preds = %for.body
+ %inc.i51 = add nsw i32 %refIdxLX.0, 1
+ br label %for.body
+
+for.end: ; preds = %entry
+ ret void
+}
+
+
+
More information about the llvm-commits
mailing list