[llvm-commits] [llvm] r134749 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp

Bob Wilson bob.wilson at apple.com
Fri Jul 8 15:09:33 PDT 2011


Author: bwilson
Date: Fri Jul  8 17:09:33 2011
New Revision: 134749

URL: http://llvm.org/viewvc/llvm-project?rev=134749&view=rev
Log:
Reapply a fixed version of r133285.
This tightens up checking for overflow in alloca sizes, based on feedback
from Duncan and John about the change in r132926.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=134749&r1=134748&r2=134749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Fri Jul  8 17:09:33 2011
@@ -30,6 +30,14 @@
   }
   
   if (BinaryOperator *I = dyn_cast<BinaryOperator>(Val)) {
+    // Cannot look past anything that might overflow.
+    OverflowingBinaryOperator *OBI = dyn_cast<OverflowingBinaryOperator>(Val);
+    if (OBI && !OBI->hasNoUnsignedWrap()) {
+      Scale = 1;
+      Offset = 0;
+      return Val;
+    }
+
     if (ConstantInt *RHS = dyn_cast<ConstantInt>(I->getOperand(1))) {
       if (I->getOpcode() == Instruction::Shl) {
         // This is a value scaled by '1 << the shift amt'.
@@ -71,11 +79,6 @@
   // This requires TargetData to get the alloca alignment and size information.
   if (!TD) return 0;
 
-  // Insist that the amount-to-allocate not overflow.
-  OverflowingBinaryOperator *OBI =
-    dyn_cast<OverflowingBinaryOperator>(AI.getOperand(0));
-  if (OBI && !(OBI->hasNoSignedWrap() || OBI->hasNoUnsignedWrap())) return 0;
-
   const PointerType *PTy = cast<PointerType>(CI.getType());
   
   BuilderTy AllocaBuilder(*Builder);





More information about the llvm-commits mailing list