Preserve HasNSW and HasNUW when constructing SCEVs for Add and Mul
authorDan Gohman <gohman@apple.com>
Fri, 9 Oct 2009 00:41:22 +0000 (00:41 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 9 Oct 2009 00:41:22 +0000 (00:41 +0000)
instructions.

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

lib/Analysis/ScalarEvolution.cpp

index 9300de11685a4b9f107f3b04ed8e7e2878084d4e..bdf31f9a706a02519acb820d3712d320ff845379 100644 (file)
@@ -2951,12 +2951,20 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
 
   Operator *U = cast<Operator>(V);
   switch (Opcode) {
-  case Instruction::Add:
+  case Instruction::Add: {
+    AddOperator *A = cast<AddOperator>(U);
     return getAddExpr(getSCEV(U->getOperand(0)),
-                      getSCEV(U->getOperand(1)));
-  case Instruction::Mul:
+                      getSCEV(U->getOperand(1)),
+                      A->hasNoUnsignedWrap(),
+                      A->hasNoSignedWrap());
+  }
+  case Instruction::Mul: {
+    MulOperator *M = cast<MulOperator>(U);
     return getMulExpr(getSCEV(U->getOperand(0)),
-                      getSCEV(U->getOperand(1)));
+                      getSCEV(U->getOperand(1)),
+                      M->hasNoUnsignedWrap(),
+                      M->hasNoSignedWrap());
+  }
   case Instruction::UDiv:
     return getUDivExpr(getSCEV(U->getOperand(0)),
                        getSCEV(U->getOperand(1)));