Fix SCEVExpander::visitSMaxExpr and SCEVExpander::visitUMaxExpr to
authorDan Gohman <gohman@apple.com>
Thu, 16 Apr 2009 16:15:25 +0000 (16:15 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 16 Apr 2009 16:15:25 +0000 (16:15 +0000)
not create ICmpInsts with operands of different types. This fixes
a regression in Applications/d/make_dparser.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69294 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolutionExpander.cpp

index 0033fb4ae4ae615a8868d96007341ced83a6c30e..6300f1ff113f756ca8729fc53ecc909bd79d0345 100644 (file)
@@ -295,9 +295,13 @@ Value *SCEVExpander::visitSignExtendExpr(SCEVSignExtendExpr *S) {
 }
 
 Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {
+  const Type *Ty = S->getType();
   Value *LHS = expand(S->getOperand(0));
+  LHS = InsertCastOfTo(CastInst::getCastOpcode(LHS, false, Ty, false), LHS, Ty);
   for (unsigned i = 1; i < S->getNumOperands(); ++i) {
     Value *RHS = expand(S->getOperand(i));
+    RHS = InsertCastOfTo(CastInst::getCastOpcode(RHS, false, Ty, false),
+                         RHS, Ty);
     Value *ICmp = new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS, "tmp", InsertPt);
     LHS = SelectInst::Create(ICmp, LHS, RHS, "smax", InsertPt);
   }
@@ -305,9 +309,13 @@ Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {
 }
 
 Value *SCEVExpander::visitUMaxExpr(SCEVUMaxExpr *S) {
+  const Type *Ty = S->getType();
   Value *LHS = expand(S->getOperand(0));
+  LHS = InsertCastOfTo(CastInst::getCastOpcode(LHS, false, Ty, false), LHS, Ty);
   for (unsigned i = 1; i < S->getNumOperands(); ++i) {
     Value *RHS = expand(S->getOperand(i));
+    RHS = InsertCastOfTo(CastInst::getCastOpcode(RHS, false, Ty, false),
+                         RHS, Ty);
     Value *ICmp = new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS, "tmp", InsertPt);
     LHS = SelectInst::Create(ICmp, LHS, RHS, "umax", InsertPt);
   }