diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 6582f368a73..5064063f29a 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -676,7 +676,7 @@ bool LoopIndexSplit::safeExitingBlock(SplitInfo &SD, continue; // Check if I is induction variable increment instruction. - if (!IndVarIncrement && I->getOpcode() == Instruction::Add) { + if (I->getOpcode() == Instruction::Add) { Value *Op0 = I->getOperand(0); Value *Op1 = I->getOperand(1); @@ -685,16 +685,23 @@ bool LoopIndexSplit::safeExitingBlock(SplitInfo &SD, if ((PN = dyn_cast(Op0))) { if ((CI = dyn_cast(Op1))) - IndVarIncrement = I; + if (CI->isOne()) { + if (!IndVarIncrement && PN == IndVar) + IndVarIncrement = I; + // else this is another loop induction variable + continue; + } } else if ((PN = dyn_cast(Op1))) { if ((CI = dyn_cast(Op0))) - IndVarIncrement = I; + if (CI->isOne()) { + if (!IndVarIncrement && PN == IndVar) + IndVarIncrement = I; + // else this is another loop induction variable + continue; + } } - - if (IndVarIncrement && PN == IndVar && CI->isOne()) - continue; - } + } // I is an Exit condition if next instruction is block terminator. // Exit condition is OK if it compares loop invariant exit value, diff --git a/test/Transforms/LoopIndexSplit/2007-09-25-UpdateIterationSpace-2.ll b/test/Transforms/LoopIndexSplit/2007-09-25-UpdateIterationSpace-2.ll new file mode 100644 index 00000000000..06f9e110967 --- /dev/null +++ b/test/Transforms/LoopIndexSplit/2007-09-25-UpdateIterationSpace-2.ll @@ -0,0 +1,59 @@ +; PR714 +; Update loop iteraton space to eliminate condition inside loop. +; RUN: llvm-as < %s | opt -loop-index-split | llvm-dis | not grep bothcond +define void @test(float* %x, i32 %ndat, float** %y, float %xcen, i32 %xmin, i32 %xmax, float %sigmal, float %contribution) { +entry: + %tmp5310 = icmp sgt i32 %xmin, %xmax ; [#uses=1] + br i1 %tmp5310, label %return, label %bb.preheader + +bb.preheader: ; preds = %entry + %tmp3031 = fpext float %contribution to double ; [#uses=1] + %tmp32 = mul double %tmp3031, 5.000000e-01 ; [#uses=1] + %tmp3839 = fpext float %sigmal to double ; [#uses=1] + br label %bb + +bb: ; preds = %bb.preheader, %cond_next45 + %i.01.0 = phi i32 [ %tmp47, %cond_next45 ], [ %xmin, %bb.preheader ] ; [#uses=4] + %k.06.0 = phi i32 [ %tmp49, %cond_next45 ], [ 0, %bb.preheader ] ; [#uses=3] + %tmp2 = icmp sgt i32 %i.01.0, -1 ; [#uses=1] + %tmp6 = icmp slt i32 %i.01.0, %ndat ; [#uses=1] + %bothcond = and i1 %tmp2, %tmp6 ; [#uses=1] + br i1 %bothcond, label %cond_true9, label %cond_next45 + +cond_true9: ; preds = %bb + %tmp12 = getelementptr float* %x, i32 %i.01.0 ; [#uses=1] + %tmp13 = load float* %tmp12, align 4 ; [#uses=1] + %tmp15 = sub float %xcen, %tmp13 ; [#uses=1] + %tmp16 = tail call float @fabsf( float %tmp15 ) ; [#uses=1] + %tmp18 = fdiv float %tmp16, %sigmal ; [#uses=1] + %tmp21 = load float** %y, align 4 ; [#uses=2] + %tmp27 = getelementptr float* %tmp21, i32 %k.06.0 ; [#uses=1] + %tmp28 = load float* %tmp27, align 4 ; [#uses=1] + %tmp2829 = fpext float %tmp28 to double ; [#uses=1] + %tmp34 = sub float -0.000000e+00, %tmp18 ; [#uses=1] + %tmp3435 = fpext float %tmp34 to double ; [#uses=1] + %tmp36 = tail call double @exp( double %tmp3435 ) ; [#uses=1] + %tmp37 = mul double %tmp32, %tmp36 ; [#uses=1] + %tmp40 = fdiv double %tmp37, %tmp3839 ; [#uses=1] + %tmp41 = add double %tmp2829, %tmp40 ; [#uses=1] + %tmp4142 = fptrunc double %tmp41 to float ; [#uses=1] + %tmp44 = getelementptr float* %tmp21, i32 %k.06.0 ; [#uses=1] + store float %tmp4142, float* %tmp44, align 4 + br label %cond_next45 + +cond_next45: ; preds = %bb, %cond_true9 + %tmp47 = add i32 %i.01.0, 1 ; [#uses=2] + %tmp49 = add i32 %k.06.0, 1 ; [#uses=1] + %tmp53 = icmp sgt i32 %tmp47, %xmax ; [#uses=1] + br i1 %tmp53, label %return.loopexit, label %bb + +return.loopexit: ; preds = %cond_next45 + br label %return + +return: ; preds = %return.loopexit, %entry + ret void +} + +declare float @fabsf(float) + +declare double @exp(double)