[llvm-commits] [llvm] r73839 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll
Nick Lewycky
nicholas at mxc.ca
Sat Jun 20 18:56:42 PDT 2009
Author: nicholas
Date: Sat Jun 20 20:56:41 2009
New Revision: 73839
URL: http://llvm.org/viewvc/llvm-project?rev=73839&view=rev
Log:
Expand this test to handle more cases (remainder and shifts) of zero.
Added:
llvm/trunk/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll
- copied, changed from r73835, llvm/trunk/test/Transforms/ConstProp/div-zero.ll
Modified:
llvm/trunk/lib/VMCore/ConstantFold.cpp
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=73839&r1=73838&r2=73839&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Sat Jun 20 20:56:41 2009
@@ -629,7 +629,7 @@
}
}
- // Handle simplifications of the RHS when a constant int.
+ // Handle simplifications when the RHS is a constant int.
if (const ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
switch (Opcode) {
case Instruction::Add:
@@ -773,13 +773,20 @@
}
}
}
-
- // 0 / x -> 0.
- if ((Opcode == Instruction::UDiv ||
- Opcode == Instruction::SDiv) &&
- CI1->isZero())
- return const_cast<Constant*>(C1);
-
+
+ switch (Opcode) {
+ case Instruction::SDiv:
+ case Instruction::UDiv:
+ case Instruction::URem:
+ case Instruction::SRem:
+ case Instruction::LShr:
+ case Instruction::AShr:
+ case Instruction::Shl:
+ if (CI1->equalsInt(0)) return const_cast<Constant*>(C1);
+ break;
+ default:
+ break;
+ }
} else if (const ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
if (const ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
APFloat C1V = CFP1->getValueAPF();
Copied: llvm/trunk/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll (from r73835, llvm/trunk/test/Transforms/ConstProp/div-zero.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll?p2=llvm/trunk/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll&p1=llvm/trunk/test/Transforms/ConstProp/div-zero.ll&r1=73835&r2=73839&rev=73839&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/div-zero.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll Sat Jun 20 20:56:41 2009
@@ -1,12 +1,11 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {ret i32 0}
+; RUN: llvm-as < %s | llvm-dis | not grep ptrtoint
; PR4424
-declare void @ext()
-
-define i32 @foo(i32 %ptr) {
-entry:
- %zero = sub i32 %ptr, %ptr ; <i32> [#uses=1]
- %div_zero = sdiv i32 %zero, ptrtoint (i32* getelementptr (i32* null,
-i32 1) to i32) ; <i32> [#uses=1]
- ret i32 %div_zero
-}
+ at G = external global i32
+ at test1 = constant i32 sdiv (i32 0, i32 ptrtoint (i32* @G to i32))
+ at test2 = constant i32 udiv (i32 0, i32 ptrtoint (i32* @G to i32))
+ at test3 = constant i32 srem (i32 0, i32 ptrtoint (i32* @G to i32))
+ at test4 = constant i32 urem (i32 0, i32 ptrtoint (i32* @G to i32))
+ at test5 = constant i32 lshr (i32 0, i32 ptrtoint (i32* @G to i32))
+ at test6 = constant i32 ashr (i32 0, i32 ptrtoint (i32* @G to i32))
+ at test7 = constant i32 shl (i32 0, i32 ptrtoint (i32* @G to i32))
More information about the llvm-commits
mailing list