1; RUN: opt < %s -data-layout="e-p:64:64:64-p1:16:16:16-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" -instcombine -S | FileCheck %s --check-prefix=LE 2; RUN: opt < %s -data-layout="E-p:64:64:64-p1:16:16:16-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" -instcombine -S | FileCheck %s --check-prefix=BE 3 4; {{ 0xDEADBEEF, 0xBA }, 0xCAFEBABE} 5@g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 } 6@g2 = constant double 1.0 7; { 0x7B, 0x06B1BFF8 } 8@g3 = constant {i64, i64} { i64 123, i64 112312312 } 9 10; Simple load 11define i32 @test1() { 12 %r = load i32, i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) 13 ret i32 %r 14 15; 0xDEADBEEF 16; LE-LABEL: @test1( 17; LE: ret i32 -559038737 18 19; 0xDEADBEEF 20; BE-LABEL: @test1( 21; BE: ret i32 -559038737 22} 23 24; PR3152 25; Load of first 16 bits of 32-bit value. 26define i16 @test2() { 27 %r = load i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*) 28 ret i16 %r 29 30; 0xBEEF 31; LE-LABEL: @test2( 32; LE: ret i16 -16657 33 34; 0xDEAD 35; BE-LABEL: @test2( 36; BE: ret i16 -8531 37} 38 39define i16 @test2_addrspacecast() { 40 %r = load i16, i16 addrspace(1)* addrspacecast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16 addrspace(1)*) 41 ret i16 %r 42 43; FIXME: Should be able to load through a constant addrspacecast. 44; 0xBEEF 45; LE-LABEL: @test2_addrspacecast( 46; XLE: ret i16 -16657 47; LE: load i16, i16 addrspace(1)* addrspacecast 48 49; 0xDEAD 50; BE-LABEL: @test2_addrspacecast( 51; XBE: ret i16 -8531 52; BE: load i16, i16 addrspace(1)* addrspacecast 53} 54 55; Load of second 16 bits of 32-bit value. 56define i16 @test3() { 57 %r = load i16, i16* getelementptr(i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 1) 58 ret i16 %r 59 60; 0xDEAD 61; LE-LABEL: @test3( 62; LE: ret i16 -8531 63 64; 0xBEEF 65; BE-LABEL: @test3( 66; BE: ret i16 -16657 67} 68 69; Load of 8 bit field + tail padding. 70define i16 @test4() { 71 %r = load i16, i16* getelementptr(i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 2) 72 ret i16 %r 73 74; 0x00BA 75; LE-LABEL: @test4( 76; LE: ret i16 186 77 78; 0xBA00 79; BE-LABEL: @test4( 80; BE: ret i16 -17920 81} 82 83; Load of double bits. 84define i64 @test6() { 85 %r = load i64, i64* bitcast(double* @g2 to i64*) 86 ret i64 %r 87 88; 0x3FF_0000000000000 89; LE-LABEL: @test6( 90; LE: ret i64 4607182418800017408 91 92; 0x3FF_0000000000000 93; BE-LABEL: @test6( 94; BE: ret i64 4607182418800017408 95} 96 97; Load of double bits. 98define i16 @test7() { 99 %r = load i16, i16* bitcast(double* @g2 to i16*) 100 ret i16 %r 101 102; 0x0000 103; LE-LABEL: @test7( 104; LE: ret i16 0 105 106; 0x3FF0 107; BE-LABEL: @test7( 108; BE: ret i16 16368 109} 110 111; Double load. 112define double @test8() { 113 %r = load double, double* bitcast({{i32,i8},i32}* @g1 to double*) 114 ret double %r 115 116; LE-LABEL: @test8( 117; LE: ret double 0xBADEADBEEF 118 119; BE-LABEL: @test8( 120; BE: ret double 0xDEADBEEFBA000000 121} 122 123 124; i128 load. 125define i128 @test9() { 126 %r = load i128, i128* bitcast({i64, i64}* @g3 to i128*) 127 ret i128 %r 128 129; 0x00000000_06B1BFF8_00000000_0000007B 130; LE-LABEL: @test9( 131; LE: ret i128 2071796475790618158476296315 132 133; 0x00000000_0000007B_00000000_06B1BFF8 134; BE-LABEL: @test9( 135; BE: ret i128 2268949521066387161080 136} 137 138; vector load. 139define <2 x i64> @test10() { 140 %r = load <2 x i64>, <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*) 141 ret <2 x i64> %r 142 143; LE-LABEL: @test10( 144; LE: ret <2 x i64> <i64 123, i64 112312312> 145 146; BE-LABEL: @test10( 147; BE: ret <2 x i64> <i64 123, i64 112312312> 148} 149 150 151; PR5287 152; { 0xA1, 0x08 } 153@g4 = internal constant { i8, i8 } { i8 -95, i8 8 } 154 155define i16 @test11() nounwind { 156entry: 157 %a = load i16, i16* bitcast ({ i8, i8 }* @g4 to i16*) 158 ret i16 %a 159 160; 0x08A1 161; LE-LABEL: @test11( 162; LE: ret i16 2209 163 164; 0xA108 165; BE-LABEL: @test11( 166; BE: ret i16 -24312 167} 168 169 170; PR5551 171@test12g = private constant [6 x i8] c"a\00b\00\00\00" 172 173define i16 @test12() { 174 %a = load i16, i16* getelementptr inbounds ([3 x i16], [3 x i16]* bitcast ([6 x i8]* @test12g to [3 x i16]*), i32 0, i64 1) 175 ret i16 %a 176 177; 0x0062 178; LE-LABEL: @test12( 179; LE: ret i16 98 180 181; 0x6200 182; BE-LABEL: @test12( 183; BE: ret i16 25088 184} 185 186 187; PR5978 188@g5 = constant i8 4 189define i1 @test13() { 190 %A = load i1, i1* bitcast (i8* @g5 to i1*) 191 ret i1 %A 192 193; LE-LABEL: @test13( 194; LE: ret i1 false 195 196; BE-LABEL: @test13( 197; BE: ret i1 false 198} 199 200@g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)] 201define i64 @test14() nounwind { 202entry: 203 %tmp = load i64, i64* bitcast ([2 x i8*]* @g6 to i64*) 204 ret i64 %tmp 205 206; LE-LABEL: @test14( 207; LE: ret i64 1 208 209; BE-LABEL: @test14( 210; BE: ret i64 1 211} 212 213; Check with address space pointers 214@g6_as1 = constant [2 x i8 addrspace(1)*] [i8 addrspace(1)* inttoptr (i16 1 to i8 addrspace(1)*), i8 addrspace(1)* inttoptr (i16 2 to i8 addrspace(1)*)] 215define i16 @test14_as1() nounwind { 216entry: 217 %tmp = load i16, i16* bitcast ([2 x i8 addrspace(1)*]* @g6_as1 to i16*) 218 ret i16 %tmp 219 220; LE: @test14_as1 221; LE: ret i16 1 222 223; BE: @test14_as1 224; BE: ret i16 1 225} 226 227define i64 @test15() nounwind { 228entry: 229 %tmp = load i64, i64* bitcast (i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @g6, i32 0, i64 1) to i64*) 230 ret i64 %tmp 231 232; LE-LABEL: @test15( 233; LE: ret i64 2 234 235; BE-LABEL: @test15( 236; BE: ret i64 2 237} 238 239@gv7 = constant [4 x i8*] [i8* null, i8* inttoptr (i64 -14 to i8*), i8* null, i8* null] 240define i64 @test16.1() { 241 %v = load i64, i64* bitcast ([4 x i8*]* @gv7 to i64*), align 8 242 ret i64 %v 243 244; LE-LABEL: @test16.1( 245; LE: ret i64 0 246 247; BE-LABEL: @test16.1( 248; BE: ret i64 0 249} 250 251define i64 @test16.2() { 252 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 1) to i64*), align 8 253 ret i64 %v 254 255; LE-LABEL: @test16.2( 256; LE: ret i64 -14 257 258; BE-LABEL: @test16.2( 259; BE: ret i64 -14 260} 261 262define i64 @test16.3() { 263 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 2) to i64*), align 8 264 ret i64 %v 265 266; LE-LABEL: @test16.3( 267; LE: ret i64 0 268 269; BE-LABEL: @test16.3( 270; BE: ret i64 0 271} 272