[llvm-commits] [llvm] r162751 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll
Benjamin Kramer
benny.kra at googlemail.com
Tue Aug 28 06:08:13 PDT 2012
Author: d0k
Date: Tue Aug 28 08:08:13 2012
New Revision: 162751
URL: http://llvm.org/viewvc/llvm-project?rev=162751&view=rev
Log:
InstCombine: Guard the transform introduced in r162743 against large ints and non-const shifts.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=162751&r1=162750&r2=162751&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Tue Aug 28 08:08:13 2012
@@ -464,11 +464,11 @@
// Udiv ((Lshl x, C1) , C2) -> x / (C2 * 1<<C1);
if (ConstantInt *C2 = dyn_cast<ConstantInt>(Op1)) {
- Value *X = 0, *C1 = 0;
- if (match(Op0, m_LShr(m_Value(X), m_Value(C1))) && C2->getBitWidth() < 65) {
- uint64_t NC = cast<ConstantInt>(C2)->getZExtValue() *
- (1<< cast<ConstantInt>(C1)->getZExtValue());
- return BinaryOperator::CreateUDiv(X, ConstantInt::get(I.getType(), NC));
+ Value *X;
+ ConstantInt *C1;
+ if (match(Op0, m_LShr(m_Value(X), m_ConstantInt(C1)))) {
+ APInt NC = C2->getValue().shl(C1->getZExtValue());
+ return BinaryOperator::CreateUDiv(X, Builder->getInt(NC));
}
}
@@ -545,11 +545,11 @@
// Sdiv ((Ashl x, C1) , C2) -> x / (C2 * 1<<C1);
if (ConstantInt *C2 = dyn_cast<ConstantInt>(Op1)) {
- Value *X = 0, *C1 = 0;
- if (match(Op0, m_AShr(m_Value(X), m_Value(C1))) && C2->getBitWidth() < 65) {
- uint64_t NC = cast<ConstantInt>(C2)->getZExtValue() *
- (1<< cast<ConstantInt>(C1)->getZExtValue());
- return BinaryOperator::CreateSDiv(X, ConstantInt::get(I.getType(), NC));
+ Value *X;
+ ConstantInt *C1;
+ if (match(Op0, m_AShr(m_Value(X), m_ConstantInt(C1)))) {
+ APInt NC = C2->getValue().shl(C1->getZExtValue());
+ return BinaryOperator::CreateSDiv(X, Builder->getInt(NC));
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll?rev=162751&r1=162750&r2=162751&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll Tue Aug 28 08:08:13 2012
@@ -49,9 +49,34 @@
ret i32 %div1
}
-define i80 @no_crash_i80(i80 %x) {
-entry:
+
+; CHECK: @udiv_i80
+; CHECK: udiv i80 %x, 400
+; CHECK: ret
+define i80 @udiv_i80(i80 %x) {
%div = lshr i80 %x, 2
%div1 = udiv i80 %div, 100
ret i80 %div1
}
+
+; CHECK: @sdiv_i80
+; CHECK: sdiv i80 %x, 400
+; CHECK: ret
+define i80 @sdiv_i80(i80 %x) {
+ %div = ashr i80 %x, 2
+ %div1 = sdiv i80 %div, 100
+ ret i80 %div1
+}
+
+
+define i32 @no_crash_notconst_sdiv(i32 %x, i32 %notconst) {
+ %div = ashr i32 %x, %notconst
+ %div1 = sdiv i32 %div, 100
+ ret i32 %div1
+}
+
+define i32 @no_crash_notconst_udiv(i32 %x, i32 %notconst) {
+ %div = lshr i32 %x, %notconst
+ %div1 = udiv i32 %div, 100
+ ret i32 %div1
+}
More information about the llvm-commits
mailing list