[llvm] r251756 - [SCEV] Don't create SCEV expressions that break LCSSA
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 31 16:21:40 PDT 2015
Author: sanjoy
Date: Sat Oct 31 18:21:40 2015
New Revision: 251756
URL: http://llvm.org/viewvc/llvm-project?rev=251756&view=rev
Log:
[SCEV] Don't create SCEV expressions that break LCSSA
Prevent `createNodeFromSelectLikePHI` from creating SCEV expressions
that break LCSSA.
A better fix for the same issue is to teach SCEVExpander to not break
LCSSA by inserting PHI nodes at appropriate places. That's planned for
the future.
Fixes PR25360.
Added:
llvm/trunk/test/Transforms/IndVarSimplify/pr25360.ll
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
llvm/trunk/test/Analysis/ScalarEvolution/smax-br-phi-idioms.ll
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=251756&r1=251755&r2=251756&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sat Oct 31 18:21:40 2015
@@ -3943,6 +3943,11 @@ const SCEV *ScalarEvolution::createNodeF
if (PN->getNumIncomingValues() == 2) {
const Loop *L = LI.getLoopFor(PN->getParent());
+ // We don't want to break LCSSA, even in a SCEV expression tree.
+ for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
+ if (LI.getLoopFor(PN->getIncomingBlock(i)) != L)
+ return nullptr;
+
// Try to match
//
// br %cond, label %left, label %right
Modified: llvm/trunk/test/Analysis/ScalarEvolution/smax-br-phi-idioms.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/smax-br-phi-idioms.ll?rev=251756&r1=251755&r2=251756&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/smax-br-phi-idioms.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/smax-br-phi-idioms.ll Sat Oct 31 18:21:40 2015
@@ -102,3 +102,27 @@ define i32 @f4(i32 %x, i32 %init, i32 %l
; CHECK-NEXT: --> %v U: full-set S: full-set
ret i32 %v
}
+
+define i32 @f5(i32* %val) {
+; CHECK-LABEL: Classifying expressions for: @f5
+entry:
+ br label %for.end
+
+for.condt:
+ br i1 true, label %for.cond.0, label %for.end
+
+for.end:
+ %inc = load i32, i32* %val
+ br i1 false, label %for.condt, label %for.cond.0
+
+for.cond.0:
+ %init = phi i32 [ 0, %for.condt ], [ %inc, %for.end ]
+
+; CHECK: %init = phi i32 [ 0, %for.condt ], [ %inc, %for.end ]
+; CHECK-NEXT: --> %init U: full-set S: full-set
+
+; Matching "through" %init will break LCSSA at the SCEV expression
+; level.
+
+ ret i32 %init
+}
Added: llvm/trunk/test/Transforms/IndVarSimplify/pr25360.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/pr25360.ll?rev=251756&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/pr25360.ll (added)
+++ llvm/trunk/test/Transforms/IndVarSimplify/pr25360.ll Sat Oct 31 18:21:40 2015
@@ -0,0 +1,33 @@
+; RUN: opt -indvars -S < %s | FileCheck %s
+
+
+; Ensure that does not crash
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f() {
+; CHECK-LABEL: @f(
+entry:
+ br label %for.end
+
+for.condt: ; preds = %for.end
+ br i1 true, label %for.cond.0, label %for.end
+
+for.end: ; preds = %for.body.3
+ %inc = select i1 undef, i32 2, i32 1
+ br i1 false, label %for.condt, label %for.cond.0
+
+for.cond.0: ; preds = %for.end, %for.condt
+ %init = phi i32 [ 0, %for.condt ], [ %inc, %for.end ]
+ br i1 true, label %for.end.13, label %for.body.9
+
+for.body.9: ; preds = %for.body.9, %for.cond.0
+ %p1.addr.22 = phi i32 [ %inc10, %for.body.9 ], [ %init, %for.cond.0 ]
+ %inc10 = add i32 %p1.addr.22, 1
+ br i1 true, label %for.end.13, label %for.body.9
+
+for.end.13: ; preds = %for.cond.7.for.end.13_crit_edge, %for.cond.0
+ %p1.addr.2.lcssa = phi i32 [ %inc10, %for.body.9 ], [ %init, %for.cond.0 ]
+ ret void
+}
More information about the llvm-commits
mailing list