aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-10-24 06:14:27 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-10-24 06:14:27 +0000
commit2a890b457674d51558ef50f035fe2aa5941391df (patch)
treeb658f4581ef7cb57b7b65d7bba010256b8c1887d
parente98f0b53c2d8668e5f3c9efeaf8dd1c1062ecc8c (diff)
downloadexternal_llvm-2a890b457674d51558ef50f035fe2aa5941391df.zip
external_llvm-2a890b457674d51558ef50f035fe2aa5941391df.tar.gz
external_llvm-2a890b457674d51558ef50f035fe2aa5941391df.tar.bz2
Don't try to create a mask when we don't need one. Fixes a crash.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58075 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/ConstantFolding.cpp10
-rw-r--r--test/Transforms/InstCombine/2008-10-23-ConstFoldWithoutMask.ll8
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index d3d0eb6..9f94ee3 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -368,10 +368,12 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
if (TD && CE->getOpcode() == Instruction::IntToPtr) {
Constant *Input = CE->getOperand(0);
unsigned InWidth = Input->getType()->getPrimitiveSizeInBits();
- Constant *Mask =
- ConstantInt::get(APInt::getLowBitsSet(InWidth,
- TD->getPointerSizeInBits()));
- Input = ConstantExpr::getAnd(Input, Mask);
+ if (TD->getPointerSizeInBits() < InWidth) {
+ Constant *Mask =
+ ConstantInt::get(APInt::getLowBitsSet(InWidth,
+ TD->getPointerSizeInBits()));
+ Input = ConstantExpr::getAnd(Input, Mask);
+ }
// Do a zext or trunc to get to the dest size.
return ConstantExpr::getIntegerCast(Input, DestTy, false);
}
diff --git a/test/Transforms/InstCombine/2008-10-23-ConstFoldWithoutMask.ll b/test/Transforms/InstCombine/2008-10-23-ConstFoldWithoutMask.ll
new file mode 100644
index 0000000..8f35a85
--- /dev/null
+++ b/test/Transforms/InstCombine/2008-10-23-ConstFoldWithoutMask.ll
@@ -0,0 +1,8 @@
+; RUN: llvm-as < %s | opt -instcombine
+; PR2940
+
+define i32 @tstid() {
+ %var0 = inttoptr i32 1 to i8* ; <i8*> [#uses=1]
+ %var2 = ptrtoint i8* %var0 to i32 ; <i32> [#uses=1]
+ ret i32 %var2
+}