[llvm] r260174 - This patch is to fix PR26529 caused by r259736.
Wei Mi via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 8 16:07:08 PST 2016
Author: wmi
Date: Mon Feb 8 18:07:08 2016
New Revision: 260174
URL: http://llvm.org/viewvc/llvm-project?rev=260174&view=rev
Log:
This patch is to fix PR26529 caused by r259736.
IndVarSimplify assumes scAddRecExpr to be expanded in literal form instead of
canonical form by calling disableCanonicalMode after it creates SCEVExpander.
When CanonicalMode is disabled, SCEVExpander::expand should always return PHI
node for scAddRecExpr. r259736 broke the assumption.
The fix is to let SCEVExpander::expand skip the reuse Value logic if
CanonicalMode is false.
In addition, Besides IndVarSimplify, LSR pass also calls disableCanonicalMode
before doing rewrite. We can remove the original check of LSRMode in reuse
Value logic and use CanonicalMode instead.
Added:
llvm/trunk/test/Analysis/ScalarEvolution/scev-canonical-mode.ll
Modified:
llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=260174&r1=260173&r2=260174&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Mon Feb 8 18:07:08 2016
@@ -1645,10 +1645,9 @@ Value *SCEVExpander::expand(const SCEV *
// Expand the expression into instructions.
SetVector<Value *> *Set = SE.getSCEVValues(S);
Value *V = nullptr;
- // If the expansion is in LSRMode, and the SCEV contains any sub scAddRecExpr
- // type SCEV, it will be expanded literally, to prevent LSR's transformed SCEV
- // from being reverted.
- if (!(LSRMode && SE.containsAddRecurrence(S))) {
+ // If the expansion is not in CanonicalMode, and the SCEV contains any
+ // sub scAddRecExpr type SCEV, it is required to expand the SCEV literally.
+ if (CanonicalMode || !SE.containsAddRecurrence(S)) {
// If S is scConstant, it may be worse to reuse an existing Value.
if (S->getSCEVType() != scConstant && Set) {
// Choose a Value from the set which dominates the insertPt.
Added: llvm/trunk/test/Analysis/ScalarEvolution/scev-canonical-mode.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/scev-canonical-mode.ll?rev=260174&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/scev-canonical-mode.ll (added)
+++ llvm/trunk/test/Analysis/ScalarEvolution/scev-canonical-mode.ll Mon Feb 8 18:07:08 2016
@@ -0,0 +1,32 @@
+; PR26529: Check the assumption of IndVarSimplify to do SCEV expansion in literal mode
+; instead of CanonicalMode is properly maintained in SCEVExpander::expand.
+; RUN: opt -indvars < %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: norecurse nounwind uwtable
+define void @ehF() #0 {
+entry:
+ br i1 undef, label %if.then.i, label %hup.exit
+
+if.then.i: ; preds = %entry
+ br i1 undef, label %for.body.lr.ph.i, label %hup.exit
+
+for.body.lr.ph.i: ; preds = %if.then.i
+ br label %for.body.i
+
+for.body.i: ; preds = %for.body.i, %for.body.lr.ph.i
+ %i.03.i = phi i32 [ 0, %for.body.lr.ph.i ], [ %inc.i, %for.body.i ]
+ %k.02.i = phi i32 [ 1, %for.body.lr.ph.i ], [ %inc5.i, %for.body.i ]
+ %inc.i = add nsw i32 %i.03.i, 1
+ %idxprom.i = sext i32 %i.03.i to i64
+ %idxprom2.i = sext i32 %k.02.i to i64
+ %inc5.i = add nsw i32 %k.02.i, 1
+ br i1 false, label %for.body.i, label %hup.exit
+
+hup.exit: ; preds = %for.body.i, %if.then.i, %entry
+ ret void
+}
+
+attributes #0 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
More information about the llvm-commits
mailing list