From d4e7f44319824998bafe1bd1c50314e1310a9ca1 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 10 Nov 2008 19:48:34 +0000 Subject: [PATCH] If the sign of exit condition and split condition does not match then do not split loop index. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58995 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopIndexSplit.cpp | 7 +- .../LoopIndexSplit/2008-11-10-Sign.ll | 69 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/LoopIndexSplit/2008-11-10-Sign.ll diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 9a5920c8b97..8c54ce372ee 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -1437,7 +1437,12 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) { if (ICMP->getPredicate() == ICmpInst::ICMP_EQ) return false; } - + + // If the predicate sign does not match then skip. + ICmpInst *CI = dyn_cast(SD.SplitCondition); + if (CI && (ExitCondition->isSignedPredicate() != CI->isSignedPredicate())) + return false; + BasicBlock *SplitCondBlock = SD.SplitCondition->getParent(); // Unable to handle triangle loops at the moment. diff --git a/test/Transforms/LoopIndexSplit/2008-11-10-Sign.ll b/test/Transforms/LoopIndexSplit/2008-11-10-Sign.ll new file mode 100644 index 00000000000..11ee0f5c452 --- /dev/null +++ b/test/Transforms/LoopIndexSplit/2008-11-10-Sign.ll @@ -0,0 +1,69 @@ +; RUN: llvm-as < %s | opt -loop-index-split -stats | not grep "loop-index-split" +; PR3029 + +@g_138 = common global i32 0 ; [#uses=3] +@g_188 = common global i32 0 ; [#uses=4] +@g_207 = common global i32 0 ; [#uses=3] +@"\01LC" = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1] +@g_102 = common global i32 0 ; [#uses=0] + +define i32 @func_119() nounwind { +entry: + %0 = volatile load i32* @g_138, align 4 ; [#uses=1] + ret i32 %0 +} + +define void @func_110(i32 %p_111) nounwind { +entry: + %0 = load i32* @g_188, align 4 ; [#uses=1] + %1 = icmp ugt i32 %0, -1572397472 ; [#uses=1] + br i1 %1, label %bb, label %bb1 + +bb: ; preds = %entry + %2 = volatile load i32* @g_138, align 4 ; [#uses=0] + ret void + +bb1: ; preds = %entry + store i32 1, i32* @g_207, align 4 + ret void +} + +define void @func_34() nounwind { +entry: + store i32 0, i32* @g_188 + %g_188.promoted = load i32* @g_188 ; [#uses=1] + br label %bb + +bb: ; preds = %func_110.exit, %entry + %g_188.tmp.0 = phi i32 [ %g_188.promoted, %entry ], [ %2, %func_110.exit ] ; [#uses=2] + %0 = icmp ugt i32 %g_188.tmp.0, -1572397472 ; [#uses=1] + br i1 %0, label %bb.i, label %bb1.i + +bb.i: ; preds = %bb + %1 = volatile load i32* @g_138, align 4 ; [#uses=0] + br label %func_110.exit + +bb1.i: ; preds = %bb + store i32 1, i32* @g_207, align 4 + br label %func_110.exit + +func_110.exit: ; preds = %bb.i, %bb1.i + %2 = add i32 %g_188.tmp.0, 1 ; [#uses=3] + %3 = icmp sgt i32 %2, 1 ; [#uses=1] + br i1 %3, label %return, label %bb + +return: ; preds = %func_110.exit + %.lcssa = phi i32 [ %2, %func_110.exit ] ; [#uses=1] + store i32 %.lcssa, i32* @g_188 + ret void +} + +define i32 @main() nounwind { +entry: + call void @func_34() nounwind + %0 = load i32* @g_207, align 4 ; [#uses=1] + %1 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), i32 %0) nounwind ; [#uses=0] + ret i32 0 +} + +declare i32 @printf(i8*, ...) nounwind