SCEVValidator: Ensure that parameters are recorded correctly

This also fixes UMax where we did not correctly keep track of the parameters.
Fixes PR12275.

Reported-By: Sebastian Pop  <sebpop@gmail.com>
llvm-svn: 152913
This commit is contained in:
Tobias Grosser 2012-03-16 10:16:28 +00:00
parent 540757b09c
commit 371badaa47
2 changed files with 37 additions and 7 deletions

View File

@ -52,7 +52,9 @@ public:
};
/// @brief Construct a result with a certain type and no parameters.
ValidatorResult(SCEVType::TYPE Type) : Type(Type) {};
ValidatorResult(SCEVType::TYPE Type) : Type(Type) {
assert(Type != SCEVType::PARAM && "Did you forget to pass the parameter");
};
/// @brief Construct a result with a certain type and a single parameter.
ValidatorResult(SCEVType::TYPE Type, const SCEV *Expr) : Type(Type) {
@ -247,7 +249,7 @@ public:
}
class ValidatorResult visitSMaxExpr(const SCEVSMaxExpr *Expr) {
ValidatorResult Return(SCEVType::INT);
ValidatorResult Return(SCEVType::INT, Expr);
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) {
ValidatorResult Op = visit(Expr->getOperand(i));
@ -262,8 +264,6 @@ public:
}
class ValidatorResult visitUMaxExpr(const SCEVUMaxExpr *Expr) {
ValidatorResult Return(SCEVType::PARAM);
// We do not support unsigned operations. If 'Expr' is constant during Scop
// execution we treat this as a parameter, otherwise we bail out.
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) {
@ -271,11 +271,9 @@ public:
if (!Op.isConstant())
return ValidatorResult(SCEVType::INVALID);
Return.merge(Op);
}
return Return;
return ValidatorResult(SCEVType::PARAM, Expr);
}
ValidatorResult visitUnknown(const SCEVUnknown *Expr) {

View File

@ -0,0 +1,32 @@
; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
target datalayout = "e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:32:32f64:64:64-f32:32:32-a0:0-n32"
target triple = "hexagon-unknown-linux-gnu"
@array = external global [64 x i8], align 8
define void @foo(i32* %A) nounwind {
entry:
br label %if.then132
if.then132:
%loaded = load i32* %A
%0 = icmp ugt i32 %loaded, 10
%umax = select i1 %0, i32 %loaded, i32 10
br label %do.body
do.body:
%indvar = phi i32 [ %3, %do.body ], [ 0, %if.then132 ]
%1 = add i32 0, %umax
%2 = sub i32 %1, %indvar
%arrayidx = getelementptr [64 x i8]* @array, i32 0, i32 %2
store i8 1, i8* %arrayidx, align 1
%3 = add i32 %indvar, 1
%exitcond = icmp eq i32 %3, 20
br i1 %exitcond, label %for.end, label %do.body
for.end:
ret void
}
;CHECK: p0: (10 umax %loaded)