[llvm-commits] [llvm] r85164 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/add-shrink.ll test/Transforms/InstCombine/add-sitofp.ll

Dan Gohman gohman at apple.com
Mon Oct 26 15:14:23 PDT 2009


Author: djg
Date: Mon Oct 26 17:14:22 2009
New Revision: 85164

URL: http://llvm.org/viewvc/llvm-project?rev=85164&view=rev
Log:
Code that checks WillNotOverflowSignedAdd before creating an Add
can safely use the NSW bit on the Add.

Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
    llvm/trunk/test/Transforms/InstCombine/add-shrink.ll
    llvm/trunk/test/Transforms/InstCombine/add-sitofp.ll

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=85164&r1=85163&r2=85164&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Oct 26 17:14:22 2009
@@ -2420,8 +2420,8 @@
           ConstantExpr::getSExt(CI, I.getType()) == RHSC &&
           WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
         // Insert the new, smaller add.
-        Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0), 
-                                           CI, "addconv");
+        Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0), 
+                                              CI, "addconv");
         return new SExtInst(NewAdd, I.getType());
       }
     }
@@ -2436,8 +2436,8 @@
           WillNotOverflowSignedAdd(LHSConv->getOperand(0),
                                    RHSConv->getOperand(0))) {
         // Insert the new integer add.
-        Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0), 
-                                           RHSConv->getOperand(0), "addconv");
+        Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0), 
+                                              RHSConv->getOperand(0), "addconv");
         return new SExtInst(NewAdd, I.getType());
       }
     }
@@ -2493,8 +2493,8 @@
           ConstantExpr::getSIToFP(CI, I.getType()) == CFP &&
           WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
         // Insert the new integer add.
-        Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0),
-                                           CI, "addconv");
+        Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
+                                              CI, "addconv");
         return new SIToFPInst(NewAdd, I.getType());
       }
     }
@@ -2509,8 +2509,8 @@
           WillNotOverflowSignedAdd(LHSConv->getOperand(0),
                                    RHSConv->getOperand(0))) {
         // Insert the new integer add.
-        Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0), 
-                                           RHSConv->getOperand(0), "addconv");
+        Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0), 
+                                              RHSConv->getOperand(0), "addconv");
         return new SIToFPInst(NewAdd, I.getType());
       }
     }

Modified: llvm/trunk/test/Transforms/InstCombine/add-shrink.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add-shrink.ll?rev=85164&r1=85163&r2=85164&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/add-shrink.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/add-shrink.ll Mon Oct 26 17:14:22 2009
@@ -1,4 +1,4 @@
-; RUN: opt < %s -instcombine -S | grep {add i32}
+; RUN: opt < %s -instcombine -S | grep {add nsw i32}
 ; RUN: opt < %s -instcombine -S | grep sext | count 1
 
 ; Should only have one sext and the add should be i32 instead of i64.

Modified: llvm/trunk/test/Transforms/InstCombine/add-sitofp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add-sitofp.ll?rev=85164&r1=85163&r2=85164&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/add-sitofp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/add-sitofp.ll Mon Oct 26 17:14:22 2009
@@ -1,4 +1,4 @@
-; RUN: opt < %s -instcombine -S | grep {add i32}
+; RUN: opt < %s -instcombine -S | grep {add nsw i32}
 
 define double @x(i32 %a, i32 %b) nounwind {
   %m = lshr i32 %a, 24





More information about the llvm-commits mailing list