[llvm] r218539 - [IndVar] Don't widen loop compare unless IV user is sign extended.
Chad Rosier
mcrosier at codeaurora.org
Fri Sep 26 13:05:35 PDT 2014
Author: mcrosier
Date: Fri Sep 26 15:05:35 2014
New Revision: 218539
URL: http://llvm.org/viewvc/llvm-project?rev=218539&view=rev
Log:
[IndVar] Don't widen loop compare unless IV user is sign extended.
PR21030
Modified:
llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/trunk/test/Transforms/IndVarSimplify/widen-loop-comp.ll
Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=218539&r1=218538&r2=218539&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Fri Sep 26 15:05:35 2014
@@ -650,7 +650,7 @@ namespace {
struct WideIVInfo {
PHINode *NarrowIV;
Type *WidestNativeType; // Widest integer type created [sz]ext
- bool IsSigned; // Was an sext user seen before a zext?
+ bool IsSigned; // Was a sext user seen before a zext?
WideIVInfo() : NarrowIV(nullptr), WidestNativeType(nullptr),
IsSigned(false) {}
@@ -936,7 +936,11 @@ bool WidenIV::WidenLoopCompare(NarrowIVD
if (!Cmp)
return false;
- bool IsSigned = CmpInst::isSigned(Cmp->getPredicate());
+ // Must be a signed compare.
+ if (!CmpInst::isSigned(Cmp->getPredicate()))
+ return false;
+
+ // Must be a signed IV user.
if (!IsSigned)
return false;
Modified: llvm/trunk/test/Transforms/IndVarSimplify/widen-loop-comp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/widen-loop-comp.ll?rev=218539&r1=218538&r2=218539&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/widen-loop-comp.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/widen-loop-comp.ll Fri Sep 26 15:05:35 2014
@@ -136,3 +136,29 @@ for.body:
for.end:
ret i32 %sum.0
}
+
+declare i32 @fn1(i8 signext)
+
+; PR21030
+; CHECK-LABEL: @test4
+; CHECK: for.body:
+; CHECK: phi i32
+; CHECK: icmp sgt i8
+
+define i32 @test4(i32 %a) {
+entry:
+ br label %for.body
+
+for.body:
+ %c.07 = phi i8 [ -3, %entry ], [ %dec, %for.body ]
+ %conv6 = zext i8 %c.07 to i32
+ %or = or i32 %a, %conv6
+ %conv3 = trunc i32 %or to i8
+ %call = call i32 @fn1(i8 signext %conv3)
+ %dec = add i8 %c.07, -1
+ %cmp = icmp sgt i8 %dec, -14
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+ ret i32 0
+}
More information about the llvm-commits
mailing list