From cffddcd72620d76e160c25780277c26d6792ca2c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 29 Jun 2009 20:34:13 +0000 Subject: [PATCH] Don't cache PHI exit values from exhaustive evaluations, because an individual exhaustive evaluation reflects only the exit value implied by an individual exit, which may differ from the actual exit value of the loop if there are other exits. This fixes PR4477. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74447 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 1 - .../IndVarSimplify/loop_evaluate9.ll | 78 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/IndVarSimplify/loop_evaluate9.ll diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 6e32dcd51fb..e38b24c0b57 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -3521,7 +3521,6 @@ ScalarEvolution::ComputeBackedgeTakenCountExhaustively(const Loop *L, if (!CondVal) return getCouldNotCompute(); if (CondVal->getValue() == uint64_t(ExitWhen)) { - ConstantEvolutionLoopExitValue[PN] = PHIVal; ++NumBruteForceTripCountsComputed; return getConstant(Type::Int32Ty, IterationNum); } diff --git a/test/Transforms/IndVarSimplify/loop_evaluate9.ll b/test/Transforms/IndVarSimplify/loop_evaluate9.ll new file mode 100644 index 00000000000..5a7a859004d --- /dev/null +++ b/test/Transforms/IndVarSimplify/loop_evaluate9.ll @@ -0,0 +1,78 @@ +; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t +; RUN: grep {\[%\]tmp5.lcssa = phi i8 \\\[ 63, \[%\]cc70a02__complex_integers__Oadd.153.exit.i \\\]} %t +; RUN: grep {\[%\]tmp4.lcssa = phi i8 \\\[ -28, \[%\]cc70a02__complex_integers__Oadd.153.exit.i \\\]} %t +; PR4477 + +; Indvars should compute the exit values in loop. + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32" +target triple = "i386-pc-linux-gnu" + %struct.cc70a02__complex_integers__complex_type = type { i8, i8 } +@.str = internal constant [13 x i8] c"fc70a00.adb\00\00", align 1 ; <[13 x i8]*> [#uses=1] + +define void @_ada_cc70a02() { +entry: + br label %bb1.i + +bb1.i: ; preds = %bb2.i, %entry + %indvar.i = phi i32 [ 0, %entry ], [ %indvar.next.i, %bb2.i ] ; [#uses=2] + %result.0.i = phi i16 [ 0, %entry ], [ %ins36.i, %bb2.i ] ; [#uses=2] + %tmp38.i = trunc i16 %result.0.i to i8 ; [#uses=2] + %tmp = add i8 %tmp38.i, 96 ; [#uses=1] + %tmp1 = icmp ugt i8 %tmp, -56 ; [#uses=1] + br i1 %tmp1, label %bb.i.i, label %bb1.i.i + +bb.i.i: ; preds = %bb1.i + tail call void @__gnat_rcheck_12(i8* getelementptr ([13 x i8]* @.str, i32 0, i32 0), i32 24) noreturn + unreachable + +bb1.i.i: ; preds = %bb1.i + %tmp41.i = lshr i16 %result.0.i, 8 ; [#uses=1] + %tmp42.i = trunc i16 %tmp41.i to i8 ; [#uses=2] + %tmp2 = add i8 %tmp42.i, 109 ; [#uses=1] + %tmp3 = icmp ugt i8 %tmp2, -56 ; [#uses=1] + br i1 %tmp3, label %bb2.i.i, label %cc70a02__complex_integers__Oadd.153.exit.i + +bb2.i.i: ; preds = %bb1.i.i + tail call void @__gnat_rcheck_12(i8* getelementptr ([13 x i8]* @.str, i32 0, i32 0), i32 24) noreturn + unreachable + +cc70a02__complex_integers__Oadd.153.exit.i: ; preds = %bb1.i.i + %tmp4 = add i8 %tmp38.i, -4 ; [#uses=2] + %tmp5 = add i8 %tmp42.i, 9 ; [#uses=2] + %tmp25.i = zext i8 %tmp4 to i16 ; [#uses=1] + %tmp33.i = zext i8 %tmp5 to i16 ; [#uses=1] + %tmp34.i = shl i16 %tmp33.i, 8 ; [#uses=1] + %ins36.i = or i16 %tmp34.i, %tmp25.i ; [#uses=1] + %tmp6 = icmp eq i32 %indvar.i, 6 ; [#uses=1] + br i1 %tmp6, label %cc70a02__complex_multiplication.170.exit, label %bb2.i + +bb2.i: ; preds = %cc70a02__complex_integers__Oadd.153.exit.i + %indvar.next.i = add i32 %indvar.i, 1 ; [#uses=1] + br label %bb1.i + +cc70a02__complex_multiplication.170.exit: ; preds = %cc70a02__complex_integers__Oadd.153.exit.i + %tmp7 = icmp eq i8 %tmp4, -28 ; [#uses=1] + %tmp8 = icmp eq i8 %tmp5, 63 ; [#uses=1] + %or.cond = and i1 %tmp8, %tmp7 ; [#uses=1] + br i1 %or.cond, label %return, label %bb1 + +bb1: ; preds = %cc70a02__complex_multiplication.170.exit + tail call void @exit(i32 1) + ret void + +return: ; preds = %cc70a02__complex_multiplication.170.exit + ret void +} + +declare fastcc void @cc70a02__complex_integers__complex.164(%struct.cc70a02__complex_integers__complex_type* noalias nocapture sret, i8 signext, i8 signext) nounwind + +declare fastcc void @cc70a02__complex_integers__Osubtract.149(%struct.cc70a02__complex_integers__complex_type* noalias sret, %struct.cc70a02__complex_integers__complex_type* byval align 4) + +declare fastcc void @cc70a02__complex_integers__Oadd.153(%struct.cc70a02__complex_integers__complex_type* noalias sret, %struct.cc70a02__complex_integers__complex_type* byval align 4, %struct.cc70a02__complex_integers__complex_type* byval align 4) + +declare fastcc void @cc70a02__complex_multiplication.170(%struct.cc70a02__complex_integers__complex_type* noalias sret, %struct.cc70a02__complex_integers__complex_type* byval align 4) + +declare void @__gnat_rcheck_12(i8*, i32) noreturn + +declare void @exit(i32) -- 2.34.1