[llvm-commits] [llvm] r84941 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp test/Transforms/ConstProp/loads.ll
Chris Lattner
sabre at nondot.org
Thu Oct 22 23:50:38 PDT 2009
Author: lattner
Date: Fri Oct 23 01:50:36 2009
New Revision: 84941
URL: http://llvm.org/viewvc/llvm-project?rev=84941&view=rev
Log:
enhance FoldReinterpretLoadFromConstPtr to handle loads of up to 32
bytes (i256).
Modified:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/test/Transforms/ConstProp/loads.ll
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=84941&r1=84940&r2=84941&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Fri Oct 23 01:50:36 2009
@@ -232,7 +232,7 @@
}
unsigned BytesLoaded = (IntType->getBitWidth() + 7) / 8;
- if (BytesLoaded > 8 || BytesLoaded == 0) return 0;
+ if (BytesLoaded > 32 || BytesLoaded == 0) return 0;
GlobalValue *GVal;
int64_t Offset;
@@ -253,16 +253,18 @@
if (uint64_t(Offset) >= TD.getTypeAllocSize(GV->getInitializer()->getType()))
return UndefValue::get(IntType);
- unsigned char RawBytes[8] = {0};
+ unsigned char RawBytes[32] = {0};
if (!ReadDataFromGlobal(GV->getInitializer(), Offset, RawBytes,
BytesLoaded, TD))
return 0;
- uint64_t ResultVal = 0;
- for (unsigned i = 0; i != BytesLoaded; ++i)
- ResultVal |= (uint64_t)RawBytes[i] << (i * 8);
+ APInt ResultVal(IntType->getBitWidth(), 0);
+ for (unsigned i = 0; i != BytesLoaded; ++i) {
+ ResultVal <<= 8;
+ ResultVal |= APInt(IntType->getBitWidth(), RawBytes[BytesLoaded-1-i]);
+ }
- return ConstantInt::get(IntType, ResultVal);
+ return ConstantInt::get(IntType->getContext(), ResultVal);
}
/// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
Modified: llvm/trunk/test/Transforms/ConstProp/loads.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/loads.ll?rev=84941&r1=84940&r2=84941&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/loads.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/loads.ll Fri Oct 23 01:50:36 2009
@@ -4,6 +4,7 @@
@test1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
@test2 = constant double 1.0
+ at test3 = constant {i64, i64} { i64 123, i64 112312312 }
; Simple load
define i32 @test1() {
@@ -66,3 +67,13 @@
; @test8
; CHECK: ret double 0xDEADBEBA
}
+
+
+; i128 load.
+define i128 @test9() {
+ %r = load i128* bitcast({i64, i64}* @test3 to i128*)
+ ret i128 %r
+
+; @test9
+; CHECK: ret i128 112312312
+}
More information about the llvm-commits
mailing list