summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/ConstProp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-23 06:23:49 +0000
committerChris Lattner <sabre@nondot.org>2009-10-23 06:23:49 +0000
commited00b80bf8409e200f5a713fca6cc5859c6140f6 (patch)
tree22f3ed5de36072df18a484e1f2eabe2a8e5d8c3b /llvm/test/Transforms/ConstProp
parent9d3ba88b1d6bcb2928bb69aa27174eb7c8e27dcb (diff)
downloadbcm5719-llvm-ed00b80bf8409e200f5a713fca6cc5859c6140f6.tar.gz
bcm5719-llvm-ed00b80bf8409e200f5a713fca6cc5859c6140f6.zip
teach libanalysis to fold int and fp loads from almost arbitrary
non-type-safe constant initializers. This sort of thing happens quite a bit for 4-byte loads out of string constants, unions, bitfields, and an interesting endianness check from sqlite, which is something like this: const int sqlite3one = 1; # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) all of these macros now constant fold away. This implements PR3152 and is based on a patch started by Eli, but heavily modified and extended. llvm-svn: 84936
Diffstat (limited to 'llvm/test/Transforms/ConstProp')
-rw-r--r--llvm/test/Transforms/ConstProp/loads.ll68
1 files changed, 68 insertions, 0 deletions
diff --git a/llvm/test/Transforms/ConstProp/loads.ll b/llvm/test/Transforms/ConstProp/loads.ll
new file mode 100644
index 00000000000..f3633cc4438
--- /dev/null
+++ b/llvm/test/Transforms/ConstProp/loads.ll
@@ -0,0 +1,68 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+@test1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
+@test2 = constant double 1.0
+
+; Simple load
+define i32 @test1() {
+ %r = load i32* getelementptr ({{i32,i8},i32}* @test1, i32 0, i32 0, i32 0)
+ ret i32 %r
+; @test1
+; CHECK: ret i32 -559038737
+}
+
+; PR3152
+; Load of first 16 bits of 32-bit value.
+define i16 @test2() {
+ %r = load i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @test1, i32 0, i32 0, i32 0) to i16*)
+ ret i16 %r
+
+; @test2
+; CHECK: ret i16 -16657
+}
+
+; Load of second 16 bits of 32-bit value.
+define i16 @test3() {
+ %r = load i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @test1, i32 0, i32 0, i32 0) to i16*), i32 1)
+ ret i16 %r
+
+; @test3
+; CHECK: ret i16 -8531
+}
+
+; Load of 8 bit field + tail padding.
+define i16 @test4() {
+ %r = load i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @test1, i32 0, i32 0, i32 0) to i16*), i32 2)
+ ret i16 %r
+; @test4
+; CHECK: ret i16 186
+}
+
+; Load of double bits.
+define i64 @test6() {
+ %r = load i64* bitcast(double* @test2 to i64*)
+ ret i64 %r
+
+; @test6
+; CHECK: ret i64 4607182418800017408
+}
+
+; Load of double bits.
+define i16 @test7() {
+ %r = load i16* bitcast(double* @test2 to i16*)
+ ret i16 %r
+
+; @test7
+; CHECK: ret i16 0
+}
+
+; Double load.
+define double @test8() {
+ %r = load double* bitcast({{i32,i8},i32}* @test1 to double*)
+ ret double %r
+
+; @test8
+; CHECK: ret double 0xDEADBEBA
+}
OpenPOWER on IntegriCloud