Teach ScalarEvolution how to fold trunc(undef) and anyext(undef) to undef.
authorDan Gohman <gohman@apple.com>
Thu, 15 Jul 2010 20:02:11 +0000 (20:02 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 15 Jul 2010 20:02:11 +0000 (20:02 +0000)
This helps LSR behave more consistently on bugpoint-reduced testcases.

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

lib/Analysis/ScalarEvolution.cpp

index 413b3b47f92a4dbabe9a6224233213c4b851c3ce..f0bc9360b16d687554fad86b1cde200c80a19402 100644 (file)
@@ -845,6 +845,13 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op,
     return getAddRecExpr(Operands, AddRec->getLoop());
   }
 
+  // As a special case, fold trunc(undef) to undef. We don't want to
+  // know too much about SCEVUnknowns, but this special case is handy
+  // and harmless.
+  if (const SCEVUnknown *U = dyn_cast<SCEVUnknown>(Op))
+    if (isa<UndefValue>(U->getValue()))
+      return getSCEV(UndefValue::get(Ty));
+
   // The cast wasn't folded; create an explicit cast node. We can reuse
   // the existing insert position since if we get here, we won't have
   // made any changes which would invalidate it.
@@ -1163,6 +1170,13 @@ const SCEV *ScalarEvolution::getAnyExtendExpr(const SCEV *Op,
     return getAddRecExpr(Ops, AR->getLoop());
   }
 
+  // As a special case, fold anyext(undef) to undef. We don't want to
+  // know too much about SCEVUnknowns, but this special case is handy
+  // and harmless.
+  if (const SCEVUnknown *U = dyn_cast<SCEVUnknown>(Op))
+    if (isa<UndefValue>(U->getValue()))
+      return getSCEV(UndefValue::get(Ty));
+
   // If the expression is obviously signed, use the sext cast value.
   if (isa<SCEVSMaxExpr>(Op))
     return SExt;