summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-07-14 20:57:04 +0000
committerDan Gohman <gohman@apple.com>2009-07-14 20:57:04 +0000
commit92b969ba80a6ed6d461c5e874db259f8c0a95290 (patch)
tree3d3eb3585777966b89bb209b306ec35ebb535b81 /llvm/lib/Analysis/ScalarEvolutionExpander.cpp
parent0c37d19feac1cc63b26bca1ec1f96406709a7021 (diff)
downloadbcm5719-llvm-92b969ba80a6ed6d461c5e874db259f8c0a95290.tar.gz
bcm5719-llvm-92b969ba80a6ed6d461c5e874db259f8c0a95290.zip
Fix the expansion of umax and smax in the case where one or more of
the operands have pointer type, so that the resulting type matches the original SCEV type, and so that unnecessary ptrtoints are avoided in common cases. llvm-svn: 75680
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolutionExpander.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
index ecfbc8ec79f..20d6e20601f 100644
--- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -609,9 +609,15 @@ Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) {
}
Value *SCEVExpander::visitSMaxExpr(const SCEVSMaxExpr *S) {
- const Type *Ty = SE.getEffectiveSCEVType(S->getType());
- Value *LHS = expandCodeFor(S->getOperand(0), Ty);
- for (unsigned i = 1; i < S->getNumOperands(); ++i) {
+ Value *LHS = expand(S->getOperand(S->getNumOperands()-1));
+ const Type *Ty = LHS->getType();
+ for (int i = S->getNumOperands()-2; i >= 0; --i) {
+ // In the case of mixed integer and pointer types, do the
+ // rest of the comparisons as integer.
+ if (S->getOperand(i)->getType() != Ty) {
+ Ty = SE.getEffectiveSCEVType(Ty);
+ LHS = InsertNoopCastOfTo(LHS, Ty);
+ }
Value *RHS = expandCodeFor(S->getOperand(i), Ty);
Value *ICmp = Builder.CreateICmpSGT(LHS, RHS, "tmp");
InsertedValues.insert(ICmp);
@@ -619,13 +625,23 @@ Value *SCEVExpander::visitSMaxExpr(const SCEVSMaxExpr *S) {
InsertedValues.insert(Sel);
LHS = Sel;
}
+ // In the case of mixed integer and pointer types, cast the
+ // final result back to the pointer type.
+ if (LHS->getType() != S->getType())
+ LHS = InsertNoopCastOfTo(LHS, S->getType());
return LHS;
}
Value *SCEVExpander::visitUMaxExpr(const SCEVUMaxExpr *S) {
- const Type *Ty = SE.getEffectiveSCEVType(S->getType());
- Value *LHS = expandCodeFor(S->getOperand(0), Ty);
- for (unsigned i = 1; i < S->getNumOperands(); ++i) {
+ Value *LHS = expand(S->getOperand(S->getNumOperands()-1));
+ const Type *Ty = LHS->getType();
+ for (int i = S->getNumOperands()-2; i >= 0; --i) {
+ // In the case of mixed integer and pointer types, do the
+ // rest of the comparisons as integer.
+ if (S->getOperand(i)->getType() != Ty) {
+ Ty = SE.getEffectiveSCEVType(Ty);
+ LHS = InsertNoopCastOfTo(LHS, Ty);
+ }
Value *RHS = expandCodeFor(S->getOperand(i), Ty);
Value *ICmp = Builder.CreateICmpUGT(LHS, RHS, "tmp");
InsertedValues.insert(ICmp);
@@ -633,6 +649,10 @@ Value *SCEVExpander::visitUMaxExpr(const SCEVUMaxExpr *S) {
InsertedValues.insert(Sel);
LHS = Sel;
}
+ // In the case of mixed integer and pointer types, cast the
+ // final result back to the pointer type.
+ if (LHS->getType() != S->getType())
+ LHS = InsertNoopCastOfTo(LHS, S->getType());
return LHS;
}
OpenPOWER on IntegriCloud