[llvm-commits] [llvm] r162755 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Benjamin Kramer benny.kra at googlemail.com
Tue Aug 28 06:59:23 PDT 2012


Author: d0k
Date: Tue Aug 28 08:59:23 2012
New Revision: 162755

URL: http://llvm.org/viewvc/llvm-project?rev=162755&view=rev
Log:
InstCombine: Defensively avoid undefined shifts by limiting the amount to the bit width.

No test case, undefined shifts get folded early, but can occur when other
transforms generate a constant. Thanks to Duncan for bringing this up.

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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=162755&r1=162754&r2=162755&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Tue Aug 28 08:59:23 2012
@@ -467,7 +467,7 @@
     Value *X;
     ConstantInt *C1;
     if (match(Op0, m_LShr(m_Value(X), m_ConstantInt(C1)))) {
-      APInt NC = C2->getValue().shl(C1->getZExtValue());
+      APInt NC = C2->getValue().shl(C1->getLimitedValue(C1->getBitWidth()-1));
       return BinaryOperator::CreateUDiv(X, Builder->getInt(NC));
     }
   }
@@ -548,7 +548,7 @@
     Value *X;
     ConstantInt *C1;
     if (match(Op0, m_AShr(m_Value(X), m_ConstantInt(C1)))) {
-      APInt NC = C2->getValue().shl(C1->getZExtValue());
+      APInt NC = C2->getValue().shl(C1->getLimitedValue(C1->getBitWidth()-1));
       return BinaryOperator::CreateSDiv(X, Builder->getInt(NC));
     }
   }





More information about the llvm-commits mailing list