[llvm-commits] [llvm] r173293 - /llvm/trunk/lib/Analysis/ConstantFolding.cpp
Patrik Hägglund H
patrik.h.hagglund at ericsson.com
Tue Jan 29 01:36:23 PST 2013
FYI: This change generates an assert for the following IR code (extract from our internal frontend). I have not looked at how to fix it yet.
target datalayout = "p:16:16"
@a = global [2 x i32] zeroinitializer
define i32 @main() {
ret i32 sub (i32 ptrtoint (i32* getelementptr inbounds ([2 x i32]* @a, i16 0, i16 1) to i32), i32 ptrtoint ([2 x i32]* @a to i32))
}
On x86_64:
Release+Asserts/bin/opt -S -O1 bar.ll
opt: /dev/shm/uabpath/master/lib/IR/Constants.cpp:498: static llvm::Constant *llvm::ConstantInt::get(llvm::Type *, const llvm::APInt &): Assertion `C->getType() == Ty->getScalarType() && "ConstantInt type doesn't match the type implied by its value!"' failed.
0 opt 0x0000000000fd5ca5 llvm::sys::PrintStackTrace(_IO_FILE*) + 37
1 opt 0x0000000000fd6193
2 libpthread.so.0 0x00007fad3dbcc6a0
3 libc.so.6 0x00007fad3cd0c945 gsignal + 53
4 libc.so.6 0x00007fad3cd0df21 abort + 385
5 libc.so.6 0x00007fad3cd05810 __assert_fail + 240
6 opt 0x0000000000ee8392
7 opt 0x0000000000d51003 llvm::ConstantFoldInstOperands(unsigned int, llvm::Type*, llvm::ArrayRef<llvm::Constant*>, llvm::DataLayout const*, llvm::TargetLibraryInfo const*) + 931
8 opt 0x0000000000d5081b llvm::ConstantFoldConstantExpression(llvm::ConstantExpr const*, llvm::DataLayout const*, llvm::TargetLibraryInfo const*) + 299
9 opt 0x0000000000d50483 llvm::ConstantFoldInstruction(llvm::Instruction*, llvm::DataLayout const*, llvm::TargetLibraryInfo const*) + 323
10 opt 0x0000000000d89188 llvm::SimplifyInstruction(llvm::Instruction*, llvm::DataLayout const*, llvm::TargetLibraryInfo const*, llvm::DominatorTree const*) + 200
11 opt 0x0000000000b7a7b4
12 opt 0x0000000000f798fc llvm::FPPassManager::runOnFunction(llvm::Function&) + 364
13 opt 0x0000000000f7912b llvm::FunctionPassManagerImpl::run(llvm::Function&) + 235
14 opt 0x0000000000f78fdd llvm::FunctionPassManager::run(llvm::Function&) + 93
15 opt 0x00000000005290f8 main + 7368
16 libc.so.6 0x00007fad3ccf8bc6 __libc_start_main + 230
17 opt 0x0000000000524039
Stack dump:
0. Program arguments: Release+Asserts/bin/opt -S -O1 ../../dev/build-gcc462/bar.ll
1. Running pass 'Early CSE' on function '@main'
Abort
-----Original Message-----
From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Benjamin Kramer
Sent: den 23 januari 2013 22:21
To: llvm-commits at cs.uiuc.edu
Subject: [llvm-commits] [llvm] r173293 - /llvm/trunk/lib/Analysis/ConstantFolding.cpp
Author: d0k
Date: Wed Jan 23 15:21:24 2013
New Revision: 173293
URL: http://llvm.org/viewvc/llvm-project?rev=173293&view=rev
Log:
ConstantFolding: Tweak r173289, it should evaluate in the intptr type, not the index type.
Modified:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=173293&r1=173292&r2=173293&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Wed Jan 23 15:21:24 2013
@@ -218,10 +218,10 @@
/// from a global, return the global and the constant. Because of /// constantexprs, this function is recursive.
static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
- int64_t &Offset, const DataLayout &TD) {
+ APInt &Offset, const DataLayout
+ &TD) {
// Trivial case, constant is the global.
if ((GV = dyn_cast<GlobalValue>(C))) {
- Offset = 0;
+ Offset.clearAllBits();
return true;
}
@@ -254,22 +254,17 @@
if (!CI) return false; // Index isn't a simple constant?
if (CI->isZero()) continue; // Not adding anything.
- // Evaluate offsets in the index type.
- APInt APOffset(CI->getBitWidth(), Offset);
-
if (StructType *ST = dyn_cast<StructType>(*GTI)) {
// N = N + Offset
- APOffset +=
- APInt(CI->getBitWidth(),
- TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue()));
+ Offset +=
+ APInt(Offset.getBitWidth(),
+
+ TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue()));
} else {
SequentialType *SQT = cast<SequentialType>(*GTI);
- APOffset +=
- APInt(CI->getBitWidth(),
- TD.getTypeAllocSize(SQT->getElementType())*CI->getSExtValue());
+ Offset += APInt(Offset.getBitWidth(),
+ TD.getTypeAllocSize(SQT->getElementType()) *
+ CI->getSExtValue());
}
-
- Offset = APOffset.getSExtValue();
}
return true;
}
@@ -432,7 +427,7 @@
if (BytesLoaded > 32 || BytesLoaded == 0) return 0;
GlobalValue *GVal;
- int64_t Offset;
+ APInt Offset(TD.getPointerSizeInBits(), 0);
if (!IsConstantOffsetFromGlobal(C, GVal, Offset, TD))
return 0;
@@ -443,14 +438,15 @@
// If we're loading off the beginning of the global, some bytes may be valid,
// but we don't try to handle this.
- if (Offset < 0) return 0;
+ if (Offset.isNegative()) return 0;
// If we're not accessing anything in this constant, the result is undefined.
- if (uint64_t(Offset) >= TD.getTypeAllocSize(GV->getInitializer()->getType()))
+ if (Offset.getZExtValue() >=
+ TD.getTypeAllocSize(GV->getInitializer()->getType()))
return UndefValue::get(IntType);
unsigned char RawBytes[32] = {0};
- if (!ReadDataFromGlobal(GV->getInitializer(), Offset, RawBytes,
+ if (!ReadDataFromGlobal(GV->getInitializer(), Offset.getZExtValue(),
+ RawBytes,
BytesLoaded, TD))
return 0;
@@ -574,7 +570,8 @@
// constant. This happens frequently when iterating over a global array.
if (Opc == Instruction::Sub && TD) {
GlobalValue *GV1, *GV2;
- int64_t Offs1, Offs2;
+ APInt Offs1(TD->getPointerSizeInBits(), 0),
+ Offs2(TD->getPointerSizeInBits(), 0);
if (IsConstantOffsetFromGlobal(Op0, GV1, Offs1, *TD))
if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, *TD) &&
_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list