1 ; RUN: opt < %s -instcombine -S | FileCheck %s 2 3 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" 4 5 @g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 } 6 @g2 = constant double 1.0 7 @g3 = constant {i64, i64} { i64 123, i64 112312312 } 8 9 ; Simple load 10 define i32 @test1() { 11 %r = load i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) 12 ret i32 %r 13 ; CHECK: @test1 14 ; CHECK: ret i32 -559038737 15 } 16 17 ; PR3152 18 ; Load of first 16 bits of 32-bit value. 19 define i16 @test2() { 20 %r = load i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*) 21 ret i16 %r 22 23 ; CHECK: @test2 24 ; CHECK: ret i16 -16657 25 } 26 27 ; Load of second 16 bits of 32-bit value. 28 define i16 @test3() { 29 %r = load i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 1) 30 ret i16 %r 31 32 ; CHECK: @test3 33 ; CHECK: ret i16 -8531 34 } 35 36 ; Load of 8 bit field + tail padding. 37 define i16 @test4() { 38 %r = load i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 2) 39 ret i16 %r 40 ; CHECK: @test4 41 ; CHECK: ret i16 186 42 } 43 44 ; Load of double bits. 45 define i64 @test6() { 46 %r = load i64* bitcast(double* @g2 to i64*) 47 ret i64 %r 48 49 ; CHECK: @test6 50 ; CHECK: ret i64 4607182418800017408 51 } 52 53 ; Load of double bits. 54 define i16 @test7() { 55 %r = load i16* bitcast(double* @g2 to i16*) 56 ret i16 %r 57 58 ; CHECK: @test7 59 ; CHECK: ret i16 0 60 } 61 62 ; Double load. 63 define double @test8() { 64 %r = load double* bitcast({{i32,i8},i32}* @g1 to double*) 65 ret double %r 66 67 ; CHECK: @test8 68 ; CHECK: ret double 0xBADEADBEEF 69 } 70 71 72 ; i128 load. 73 define i128 @test9() { 74 %r = load i128* bitcast({i64, i64}* @g3 to i128*) 75 ret i128 %r 76 77 ; CHECK: @test9 78 ; CHECK: ret i128 2071796475790618158476296315 79 } 80 81 ; vector load. 82 define <2 x i64> @test10() { 83 %r = load <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*) 84 ret <2 x i64> %r 85 86 ; CHECK: @test10 87 ; CHECK: ret <2 x i64> <i64 123, i64 112312312> 88 } 89 90 91 ; PR5287 92 @g4 = internal constant { i8, i8 } { i8 -95, i8 8 } 93 94 define i16 @test11() nounwind { 95 entry: 96 %a = load i16* bitcast ({ i8, i8 }* @g4 to i16*) 97 ret i16 %a 98 99 ; CHECK: @test11 100 ; CHECK: ret i16 2209 101 } 102 103 104 ; PR5551 105 @test12g = private constant [6 x i8] c"a\00b\00\00\00" 106 107 define i16 @test12() { 108 %a = load i16* getelementptr inbounds ([3 x i16]* bitcast ([6 x i8]* @test12g to [3 x i16]*), i32 0, i64 1) 109 ret i16 %a 110 ; CHECK: @test12 111 ; CHECK: ret i16 98 112 } 113 114 115 ; PR5978 116 @g5 = constant i8 4 117 define i1 @test13() { 118 %A = load i1* bitcast (i8* @g5 to i1*) 119 ret i1 %A 120 ; CHECK: @test13 121 ; CHECK: ret i1 false 122 } 123 124 @g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)] 125 define i64 @test14() nounwind { 126 entry: 127 %tmp = load i64* bitcast ([2 x i8*]* @g6 to i64*) 128 ret i64 %tmp 129 ; CHECK: @test14 130 ; CHECK: ret i64 1 131 } 132 133 define i64 @test15() nounwind { 134 entry: 135 %tmp = load i64* bitcast (i8** getelementptr inbounds ([2 x i8*]* @g6, i32 0, i64 1) to i64*) 136 ret i64 %tmp 137 ; CHECK: @test15 138 ; CHECK: ret i64 2 139 } 140