1f4a2713aSLionel Sambuc; RUN: opt < %s -instcombine -S | FileCheck %s 2f4a2713aSLionel Sambuc 3*0a6a1f1dSLionel Sambuctarget datalayout = "e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64" 4f4a2713aSLionel Sambuc 5f4a2713aSLionel Sambuc%intstruct = type { i32 } 6f4a2713aSLionel Sambuc%pair = type { i32, i32 } 7f4a2713aSLionel Sambuc%struct.B = type { double } 8f4a2713aSLionel Sambuc%struct.A = type { %struct.B, i32, i32 } 9*0a6a1f1dSLionel Sambuc%struct.C = type { [7 x i8] } 10f4a2713aSLionel Sambuc 11f4a2713aSLionel Sambuc 12f4a2713aSLionel Sambuc@Global = constant [10 x i8] c"helloworld" 13f4a2713aSLionel Sambuc@Global_as1 = addrspace(1) constant [10 x i8] c"helloworld" 14f4a2713aSLionel Sambuc 15f4a2713aSLionel Sambuc; Test noop elimination 16f4a2713aSLionel Sambucdefine i32* @test1(i32* %I) { 17f4a2713aSLionel Sambuc %A = getelementptr i32* %I, i64 0 18f4a2713aSLionel Sambuc ret i32* %A 19f4a2713aSLionel Sambuc; CHECK-LABEL: @test1( 20f4a2713aSLionel Sambuc; CHECK: ret i32* %I 21f4a2713aSLionel Sambuc} 22f4a2713aSLionel Sambuc 23f4a2713aSLionel Sambucdefine i32 addrspace(1)* @test1_as1(i32 addrspace(1)* %I) { 24f4a2713aSLionel Sambuc %A = getelementptr i32 addrspace(1)* %I, i64 0 25f4a2713aSLionel Sambuc ret i32 addrspace(1)* %A 26f4a2713aSLionel Sambuc; CHECK-LABEL: @test1_as1( 27f4a2713aSLionel Sambuc; CHECK: ret i32 addrspace(1)* %I 28f4a2713aSLionel Sambuc} 29f4a2713aSLionel Sambuc 30f4a2713aSLionel Sambuc; Test noop elimination 31f4a2713aSLionel Sambucdefine i32* @test2(i32* %I) { 32f4a2713aSLionel Sambuc %A = getelementptr i32* %I 33f4a2713aSLionel Sambuc ret i32* %A 34f4a2713aSLionel Sambuc; CHECK-LABEL: @test2( 35f4a2713aSLionel Sambuc; CHECK: ret i32* %I 36f4a2713aSLionel Sambuc} 37f4a2713aSLionel Sambuc 38f4a2713aSLionel Sambuc; Test that two array indexing geps fold 39f4a2713aSLionel Sambucdefine i32* @test3(i32* %I) { 40f4a2713aSLionel Sambuc %A = getelementptr i32* %I, i64 17 41f4a2713aSLionel Sambuc %B = getelementptr i32* %A, i64 4 42f4a2713aSLionel Sambuc ret i32* %B 43f4a2713aSLionel Sambuc; CHECK-LABEL: @test3( 44f4a2713aSLionel Sambuc; CHECK: getelementptr i32* %I, i64 21 45f4a2713aSLionel Sambuc} 46f4a2713aSLionel Sambuc 47f4a2713aSLionel Sambuc; Test that two getelementptr insts fold 48f4a2713aSLionel Sambucdefine i32* @test4({ i32 }* %I) { 49f4a2713aSLionel Sambuc %A = getelementptr { i32 }* %I, i64 1 50f4a2713aSLionel Sambuc %B = getelementptr { i32 }* %A, i64 0, i32 0 51f4a2713aSLionel Sambuc ret i32* %B 52f4a2713aSLionel Sambuc; CHECK-LABEL: @test4( 53f4a2713aSLionel Sambuc; CHECK: getelementptr { i32 }* %I, i64 1, i32 0 54f4a2713aSLionel Sambuc} 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambucdefine void @test5(i8 %B) { 57f4a2713aSLionel Sambuc ; This should be turned into a constexpr instead of being an instruction 58f4a2713aSLionel Sambuc %A = getelementptr [10 x i8]* @Global, i64 0, i64 4 59f4a2713aSLionel Sambuc store i8 %B, i8* %A 60f4a2713aSLionel Sambuc ret void 61f4a2713aSLionel Sambuc; CHECK-LABEL: @test5( 62f4a2713aSLionel Sambuc; CHECK: store i8 %B, i8* getelementptr inbounds ([10 x i8]* @Global, i64 0, i64 4) 63f4a2713aSLionel Sambuc} 64f4a2713aSLionel Sambuc 65f4a2713aSLionel Sambucdefine void @test5_as1(i8 %B) { 66f4a2713aSLionel Sambuc ; This should be turned into a constexpr instead of being an instruction 67f4a2713aSLionel Sambuc %A = getelementptr [10 x i8] addrspace(1)* @Global_as1, i16 0, i16 4 68f4a2713aSLionel Sambuc store i8 %B, i8 addrspace(1)* %A 69f4a2713aSLionel Sambuc ret void 70f4a2713aSLionel Sambuc; CHECK-LABEL: @test5_as1( 71f4a2713aSLionel Sambuc; CHECK: store i8 %B, i8 addrspace(1)* getelementptr inbounds ([10 x i8] addrspace(1)* @Global_as1, i16 0, i16 4) 72f4a2713aSLionel Sambuc} 73f4a2713aSLionel Sambuc 74f4a2713aSLionel Sambuc%as1_ptr_struct = type { i32 addrspace(1)* } 75f4a2713aSLionel Sambuc%as2_ptr_struct = type { i32 addrspace(2)* } 76f4a2713aSLionel Sambuc 77f4a2713aSLionel Sambuc@global_as2 = addrspace(2) global i32 zeroinitializer 78f4a2713aSLionel Sambuc@global_as1_as2_ptr = addrspace(1) global %as2_ptr_struct { i32 addrspace(2)* @global_as2 } 79f4a2713aSLionel Sambuc 80f4a2713aSLionel Sambuc; This should be turned into a constexpr instead of being an instruction 81f4a2713aSLionel Sambucdefine void @test_evaluate_gep_nested_as_ptrs(i32 addrspace(2)* %B) { 82f4a2713aSLionel Sambuc; CHECK-LABEL: @test_evaluate_gep_nested_as_ptrs( 83f4a2713aSLionel Sambuc; CHECK-NEXT: store i32 addrspace(2)* %B, i32 addrspace(2)* addrspace(1)* getelementptr inbounds (%as2_ptr_struct addrspace(1)* @global_as1_as2_ptr, i16 0, i32 0), align 8 84f4a2713aSLionel Sambuc; CHECK-NEXT: ret void 85f4a2713aSLionel Sambuc %A = getelementptr %as2_ptr_struct addrspace(1)* @global_as1_as2_ptr, i16 0, i32 0 86f4a2713aSLionel Sambuc store i32 addrspace(2)* %B, i32 addrspace(2)* addrspace(1)* %A 87f4a2713aSLionel Sambuc ret void 88f4a2713aSLionel Sambuc} 89f4a2713aSLionel Sambuc 90f4a2713aSLionel Sambuc@arst = addrspace(1) global [4 x i8 addrspace(2)*] zeroinitializer 91f4a2713aSLionel Sambuc 92f4a2713aSLionel Sambucdefine void @test_evaluate_gep_as_ptrs_array(i8 addrspace(2)* %B) { 93f4a2713aSLionel Sambuc; CHECK-LABEL: @test_evaluate_gep_as_ptrs_array( 94f4a2713aSLionel Sambuc; CHECK-NEXT: store i8 addrspace(2)* %B, i8 addrspace(2)* addrspace(1)* getelementptr inbounds ([4 x i8 addrspace(2)*] addrspace(1)* @arst, i16 0, i16 2), align 4 95f4a2713aSLionel Sambuc 96f4a2713aSLionel Sambuc; CHECK-NEXT: ret void 97f4a2713aSLionel Sambuc %A = getelementptr [4 x i8 addrspace(2)*] addrspace(1)* @arst, i16 0, i16 2 98f4a2713aSLionel Sambuc store i8 addrspace(2)* %B, i8 addrspace(2)* addrspace(1)* %A 99f4a2713aSLionel Sambuc ret void 100f4a2713aSLionel Sambuc} 101f4a2713aSLionel Sambuc 102f4a2713aSLionel Sambucdefine i32* @test7(i32* %I, i64 %C, i64 %D) { 103f4a2713aSLionel Sambuc %A = getelementptr i32* %I, i64 %C 104f4a2713aSLionel Sambuc %B = getelementptr i32* %A, i64 %D 105f4a2713aSLionel Sambuc ret i32* %B 106f4a2713aSLionel Sambuc; CHECK-LABEL: @test7( 107f4a2713aSLionel Sambuc; CHECK: %A.sum = add i64 %C, %D 108f4a2713aSLionel Sambuc; CHECK: getelementptr i32* %I, i64 %A.sum 109f4a2713aSLionel Sambuc} 110f4a2713aSLionel Sambuc 111f4a2713aSLionel Sambucdefine i8* @test8([10 x i32]* %X) { 112f4a2713aSLionel Sambuc ;; Fold into the cast. 113f4a2713aSLionel Sambuc %A = getelementptr [10 x i32]* %X, i64 0, i64 0 114f4a2713aSLionel Sambuc %B = bitcast i32* %A to i8* 115f4a2713aSLionel Sambuc ret i8* %B 116f4a2713aSLionel Sambuc; CHECK-LABEL: @test8( 117f4a2713aSLionel Sambuc; CHECK: bitcast [10 x i32]* %X to i8* 118f4a2713aSLionel Sambuc} 119f4a2713aSLionel Sambuc 120f4a2713aSLionel Sambucdefine i32 @test9() { 121f4a2713aSLionel Sambuc %A = getelementptr { i32, double }* null, i32 0, i32 1 122f4a2713aSLionel Sambuc %B = ptrtoint double* %A to i32 123f4a2713aSLionel Sambuc ret i32 %B 124f4a2713aSLionel Sambuc; CHECK-LABEL: @test9( 125f4a2713aSLionel Sambuc; CHECK: ret i32 8 126f4a2713aSLionel Sambuc} 127f4a2713aSLionel Sambuc 128f4a2713aSLionel Sambucdefine i1 @test10({ i32, i32 }* %x, { i32, i32 }* %y) { 129f4a2713aSLionel Sambuc %tmp.1 = getelementptr { i32, i32 }* %x, i32 0, i32 1 130f4a2713aSLionel Sambuc %tmp.3 = getelementptr { i32, i32 }* %y, i32 0, i32 1 131f4a2713aSLionel Sambuc ;; seteq x, y 132f4a2713aSLionel Sambuc %tmp.4 = icmp eq i32* %tmp.1, %tmp.3 133f4a2713aSLionel Sambuc ret i1 %tmp.4 134f4a2713aSLionel Sambuc; CHECK-LABEL: @test10( 135f4a2713aSLionel Sambuc; CHECK: icmp eq { i32, i32 }* %x, %y 136f4a2713aSLionel Sambuc} 137f4a2713aSLionel Sambuc 138f4a2713aSLionel Sambucdefine i1 @test11({ i32, i32 }* %X) { 139f4a2713aSLionel Sambuc %P = getelementptr { i32, i32 }* %X, i32 0, i32 0 140f4a2713aSLionel Sambuc %Q = icmp eq i32* %P, null 141f4a2713aSLionel Sambuc ret i1 %Q 142f4a2713aSLionel Sambuc; CHECK-LABEL: @test11( 143f4a2713aSLionel Sambuc; CHECK: icmp eq { i32, i32 }* %X, null 144f4a2713aSLionel Sambuc} 145f4a2713aSLionel Sambuc 146f4a2713aSLionel Sambuc 147f4a2713aSLionel Sambuc; PR4748 148f4a2713aSLionel Sambucdefine i32 @test12(%struct.A* %a) { 149f4a2713aSLionel Sambucentry: 150f4a2713aSLionel Sambuc %g3 = getelementptr %struct.A* %a, i32 0, i32 1 151f4a2713aSLionel Sambuc store i32 10, i32* %g3, align 4 152f4a2713aSLionel Sambuc 153f4a2713aSLionel Sambuc %g4 = getelementptr %struct.A* %a, i32 0, i32 0 154f4a2713aSLionel Sambuc 155f4a2713aSLionel Sambuc %new_a = bitcast %struct.B* %g4 to %struct.A* 156f4a2713aSLionel Sambuc 157f4a2713aSLionel Sambuc %g5 = getelementptr %struct.A* %new_a, i32 0, i32 1 158f4a2713aSLionel Sambuc %a_a = load i32* %g5, align 4 159f4a2713aSLionel Sambuc ret i32 %a_a 160f4a2713aSLionel Sambuc; CHECK-LABEL: @test12( 161f4a2713aSLionel Sambuc; CHECK: getelementptr %struct.A* %a, i64 0, i32 1 162f4a2713aSLionel Sambuc; CHECK-NEXT: store i32 10, i32* %g3 163f4a2713aSLionel Sambuc; CHECK-NEXT: ret i32 10 164f4a2713aSLionel Sambuc} 165f4a2713aSLionel Sambuc 166f4a2713aSLionel Sambuc 167f4a2713aSLionel Sambuc; PR2235 168f4a2713aSLionel Sambuc%S = type { i32, [ 100 x i32] } 169f4a2713aSLionel Sambucdefine i1 @test13(i64 %X, %S* %P) { 170f4a2713aSLionel Sambuc %A = getelementptr inbounds %S* %P, i32 0, i32 1, i64 %X 171f4a2713aSLionel Sambuc %B = getelementptr inbounds %S* %P, i32 0, i32 0 172f4a2713aSLionel Sambuc %C = icmp eq i32* %A, %B 173f4a2713aSLionel Sambuc ret i1 %C 174f4a2713aSLionel Sambuc; CHECK-LABEL: @test13( 175f4a2713aSLionel Sambuc; CHECK: %C = icmp eq i64 %X, -1 176f4a2713aSLionel Sambuc} 177f4a2713aSLionel Sambuc 178f4a2713aSLionel Sambucdefine <2 x i1> @test13_vector(<2 x i64> %X, <2 x %S*> %P) nounwind { 179f4a2713aSLionel Sambuc; CHECK-LABEL: @test13_vector( 180f4a2713aSLionel Sambuc; CHECK-NEXT: shl nuw <2 x i64> %X, <i64 2, i64 2> 181f4a2713aSLionel Sambuc; CHECK-NEXT: add <2 x i64> %A.idx, <i64 4, i64 4> 182f4a2713aSLionel Sambuc; CHECK-NEXT: icmp eq <2 x i64> %A.offs, zeroinitializer 183f4a2713aSLionel Sambuc %A = getelementptr inbounds <2 x %S*> %P, <2 x i64> zeroinitializer, <2 x i32> <i32 1, i32 1>, <2 x i64> %X 184f4a2713aSLionel Sambuc %B = getelementptr inbounds <2 x %S*> %P, <2 x i64> <i64 0, i64 0>, <2 x i32> <i32 0, i32 0> 185f4a2713aSLionel Sambuc %C = icmp eq <2 x i32*> %A, %B 186f4a2713aSLionel Sambuc ret <2 x i1> %C 187f4a2713aSLionel Sambuc} 188f4a2713aSLionel Sambuc 189f4a2713aSLionel Sambucdefine i1 @test13_as1(i16 %X, %S addrspace(1)* %P) { 190f4a2713aSLionel Sambuc; CHECK-LABEL: @test13_as1( 191f4a2713aSLionel Sambuc; CHECK-NEXT: %C = icmp eq i16 %X, -1 192f4a2713aSLionel Sambuc; CHECK-NEXT: ret i1 %C 193f4a2713aSLionel Sambuc %A = getelementptr inbounds %S addrspace(1)* %P, i16 0, i32 1, i16 %X 194f4a2713aSLionel Sambuc %B = getelementptr inbounds %S addrspace(1)* %P, i16 0, i32 0 195f4a2713aSLionel Sambuc %C = icmp eq i32 addrspace(1)* %A, %B 196f4a2713aSLionel Sambuc ret i1 %C 197f4a2713aSLionel Sambuc} 198f4a2713aSLionel Sambuc 199f4a2713aSLionel Sambucdefine <2 x i1> @test13_vector_as1(<2 x i16> %X, <2 x %S addrspace(1)*> %P) { 200f4a2713aSLionel Sambuc; CHECK-LABEL: @test13_vector_as1( 201f4a2713aSLionel Sambuc; CHECK-NEXT: shl nuw <2 x i16> %X, <i16 2, i16 2> 202f4a2713aSLionel Sambuc; CHECK-NEXT: add <2 x i16> %A.idx, <i16 4, i16 4> 203f4a2713aSLionel Sambuc; CHECK-NEXT: icmp eq <2 x i16> %A.offs, zeroinitializer 204f4a2713aSLionel Sambuc; CHECK-NEXT: ret <2 x i1> 205f4a2713aSLionel Sambuc %A = getelementptr inbounds <2 x %S addrspace(1)*> %P, <2 x i16> <i16 0, i16 0>, <2 x i32> <i32 1, i32 1>, <2 x i16> %X 206f4a2713aSLionel Sambuc %B = getelementptr inbounds <2 x %S addrspace(1)*> %P, <2 x i16> <i16 0, i16 0>, <2 x i32> <i32 0, i32 0> 207f4a2713aSLionel Sambuc %C = icmp eq <2 x i32 addrspace(1)*> %A, %B 208f4a2713aSLionel Sambuc ret <2 x i1> %C 209f4a2713aSLionel Sambuc} 210f4a2713aSLionel Sambuc 211f4a2713aSLionel Sambucdefine i1 @test13_i32(i32 %X, %S* %P) { 212f4a2713aSLionel Sambuc; CHECK-LABEL: @test13_i32( 213f4a2713aSLionel Sambuc; CHECK: %C = icmp eq i32 %X, -1 214f4a2713aSLionel Sambuc %A = getelementptr inbounds %S* %P, i32 0, i32 1, i32 %X 215f4a2713aSLionel Sambuc %B = getelementptr inbounds %S* %P, i32 0, i32 0 216f4a2713aSLionel Sambuc %C = icmp eq i32* %A, %B 217f4a2713aSLionel Sambuc ret i1 %C 218f4a2713aSLionel Sambuc} 219f4a2713aSLionel Sambuc 220f4a2713aSLionel Sambucdefine i1 @test13_i16(i16 %X, %S* %P) { 221f4a2713aSLionel Sambuc; CHECK-LABEL: @test13_i16( 222f4a2713aSLionel Sambuc; CHECK: %C = icmp eq i16 %X, -1 223f4a2713aSLionel Sambuc %A = getelementptr inbounds %S* %P, i16 0, i32 1, i16 %X 224f4a2713aSLionel Sambuc %B = getelementptr inbounds %S* %P, i16 0, i32 0 225f4a2713aSLionel Sambuc %C = icmp eq i32* %A, %B 226f4a2713aSLionel Sambuc ret i1 %C 227f4a2713aSLionel Sambuc} 228f4a2713aSLionel Sambuc 229f4a2713aSLionel Sambucdefine i1 @test13_i128(i128 %X, %S* %P) { 230f4a2713aSLionel Sambuc; CHECK-LABEL: @test13_i128( 231f4a2713aSLionel Sambuc; CHECK: %C = icmp eq i64 %1, -1 232f4a2713aSLionel Sambuc %A = getelementptr inbounds %S* %P, i128 0, i32 1, i128 %X 233f4a2713aSLionel Sambuc %B = getelementptr inbounds %S* %P, i128 0, i32 0 234f4a2713aSLionel Sambuc %C = icmp eq i32* %A, %B 235f4a2713aSLionel Sambuc ret i1 %C 236f4a2713aSLionel Sambuc} 237f4a2713aSLionel Sambuc 238f4a2713aSLionel Sambuc 239f4a2713aSLionel Sambuc@G = external global [3 x i8] 240f4a2713aSLionel Sambucdefine i8* @test14(i32 %Idx) { 241f4a2713aSLionel Sambuc %idx = zext i32 %Idx to i64 242f4a2713aSLionel Sambuc %tmp = getelementptr i8* getelementptr ([3 x i8]* @G, i32 0, i32 0), i64 %idx 243f4a2713aSLionel Sambuc ret i8* %tmp 244f4a2713aSLionel Sambuc; CHECK-LABEL: @test14( 245f4a2713aSLionel Sambuc; CHECK: getelementptr [3 x i8]* @G, i64 0, i64 %idx 246f4a2713aSLionel Sambuc} 247f4a2713aSLionel Sambuc 248f4a2713aSLionel Sambuc 249f4a2713aSLionel Sambuc; Test folding of constantexpr geps into normal geps. 250f4a2713aSLionel Sambuc@Array = external global [40 x i32] 251f4a2713aSLionel Sambucdefine i32 *@test15(i64 %X) { 252f4a2713aSLionel Sambuc %A = getelementptr i32* getelementptr ([40 x i32]* @Array, i64 0, i64 0), i64 %X 253f4a2713aSLionel Sambuc ret i32* %A 254f4a2713aSLionel Sambuc; CHECK-LABEL: @test15( 255f4a2713aSLionel Sambuc; CHECK: getelementptr [40 x i32]* @Array, i64 0, i64 %X 256f4a2713aSLionel Sambuc} 257f4a2713aSLionel Sambuc 258f4a2713aSLionel Sambuc 259f4a2713aSLionel Sambucdefine i32* @test16(i32* %X, i32 %Idx) { 260f4a2713aSLionel Sambuc %R = getelementptr i32* %X, i32 %Idx 261f4a2713aSLionel Sambuc ret i32* %R 262f4a2713aSLionel Sambuc; CHECK-LABEL: @test16( 263f4a2713aSLionel Sambuc; CHECK: sext i32 %Idx to i64 264f4a2713aSLionel Sambuc} 265f4a2713aSLionel Sambuc 266f4a2713aSLionel Sambuc 267f4a2713aSLionel Sambucdefine i1 @test17(i16* %P, i32 %I, i32 %J) { 268f4a2713aSLionel Sambuc %X = getelementptr inbounds i16* %P, i32 %I 269f4a2713aSLionel Sambuc %Y = getelementptr inbounds i16* %P, i32 %J 270f4a2713aSLionel Sambuc %C = icmp ult i16* %X, %Y 271f4a2713aSLionel Sambuc ret i1 %C 272f4a2713aSLionel Sambuc; CHECK-LABEL: @test17( 273f4a2713aSLionel Sambuc; CHECK: %C = icmp slt i32 %I, %J 274f4a2713aSLionel Sambuc} 275f4a2713aSLionel Sambuc 276f4a2713aSLionel Sambucdefine i1 @test18(i16* %P, i32 %I) { 277f4a2713aSLionel Sambuc %X = getelementptr inbounds i16* %P, i32 %I 278f4a2713aSLionel Sambuc %C = icmp ult i16* %X, %P 279f4a2713aSLionel Sambuc ret i1 %C 280f4a2713aSLionel Sambuc; CHECK-LABEL: @test18( 281f4a2713aSLionel Sambuc; CHECK: %C = icmp slt i32 %I, 0 282f4a2713aSLionel Sambuc} 283f4a2713aSLionel Sambuc 284f4a2713aSLionel Sambuc; Larger than the pointer size for a non-zero address space 285f4a2713aSLionel Sambucdefine i1 @test18_as1(i16 addrspace(1)* %P, i32 %I) { 286f4a2713aSLionel Sambuc; CHECK-LABEL: @test18_as1( 287f4a2713aSLionel Sambuc; CHECK-NEXT: %1 = trunc i32 %I to i16 288f4a2713aSLionel Sambuc; CHECK-NEXT: %C = icmp slt i16 %1, 0 289f4a2713aSLionel Sambuc; CHECK-NEXT: ret i1 %C 290f4a2713aSLionel Sambuc %X = getelementptr inbounds i16 addrspace(1)* %P, i32 %I 291f4a2713aSLionel Sambuc %C = icmp ult i16 addrspace(1)* %X, %P 292f4a2713aSLionel Sambuc ret i1 %C 293f4a2713aSLionel Sambuc} 294f4a2713aSLionel Sambuc 295f4a2713aSLionel Sambuc; Smaller than the pointer size for a non-zero address space 296f4a2713aSLionel Sambucdefine i1 @test18_as1_i32(i16 addrspace(1)* %P, i32 %I) { 297f4a2713aSLionel Sambuc; CHECK-LABEL: @test18_as1_i32( 298f4a2713aSLionel Sambuc; CHECK-NEXT: %1 = trunc i32 %I to i16 299f4a2713aSLionel Sambuc; CHECK-NEXT: %C = icmp slt i16 %1, 0 300f4a2713aSLionel Sambuc; CHECK-NEXT: ret i1 %C 301f4a2713aSLionel Sambuc %X = getelementptr inbounds i16 addrspace(1)* %P, i32 %I 302f4a2713aSLionel Sambuc %C = icmp ult i16 addrspace(1)* %X, %P 303f4a2713aSLionel Sambuc ret i1 %C 304f4a2713aSLionel Sambuc} 305f4a2713aSLionel Sambuc 306f4a2713aSLionel Sambuc; Smaller than pointer size 307f4a2713aSLionel Sambucdefine i1 @test18_i16(i16* %P, i16 %I) { 308f4a2713aSLionel Sambuc; CHECK-LABEL: @test18_i16( 309f4a2713aSLionel Sambuc; CHECK: %C = icmp slt i16 %I, 0 310f4a2713aSLionel Sambuc %X = getelementptr inbounds i16* %P, i16 %I 311f4a2713aSLionel Sambuc %C = icmp ult i16* %X, %P 312f4a2713aSLionel Sambuc ret i1 %C 313f4a2713aSLionel Sambuc} 314f4a2713aSLionel Sambuc 315f4a2713aSLionel Sambuc; Same as pointer size 316f4a2713aSLionel Sambucdefine i1 @test18_i64(i16* %P, i64 %I) { 317f4a2713aSLionel Sambuc; CHECK-LABEL: @test18_i64( 318f4a2713aSLionel Sambuc; CHECK: %C = icmp slt i64 %I, 0 319f4a2713aSLionel Sambuc %X = getelementptr inbounds i16* %P, i64 %I 320f4a2713aSLionel Sambuc %C = icmp ult i16* %X, %P 321f4a2713aSLionel Sambuc ret i1 %C 322f4a2713aSLionel Sambuc} 323f4a2713aSLionel Sambuc 324f4a2713aSLionel Sambuc; Larger than the pointer size 325f4a2713aSLionel Sambucdefine i1 @test18_i128(i16* %P, i128 %I) { 326f4a2713aSLionel Sambuc; CHECK-LABEL: @test18_i128( 327f4a2713aSLionel Sambuc; CHECK: %C = icmp slt i64 %1, 0 328f4a2713aSLionel Sambuc %X = getelementptr inbounds i16* %P, i128 %I 329f4a2713aSLionel Sambuc %C = icmp ult i16* %X, %P 330f4a2713aSLionel Sambuc ret i1 %C 331f4a2713aSLionel Sambuc} 332f4a2713aSLionel Sambuc 333f4a2713aSLionel Sambucdefine i32 @test19(i32* %P, i32 %A, i32 %B) { 334f4a2713aSLionel Sambuc %tmp.4 = getelementptr inbounds i32* %P, i32 %A 335f4a2713aSLionel Sambuc %tmp.9 = getelementptr inbounds i32* %P, i32 %B 336f4a2713aSLionel Sambuc %tmp.10 = icmp eq i32* %tmp.4, %tmp.9 337f4a2713aSLionel Sambuc %tmp.11 = zext i1 %tmp.10 to i32 338f4a2713aSLionel Sambuc ret i32 %tmp.11 339f4a2713aSLionel Sambuc; CHECK-LABEL: @test19( 340f4a2713aSLionel Sambuc; CHECK: icmp eq i32 %A, %B 341f4a2713aSLionel Sambuc} 342f4a2713aSLionel Sambuc 343f4a2713aSLionel Sambucdefine i32 @test20(i32* %P, i32 %A, i32 %B) { 344f4a2713aSLionel Sambuc %tmp.4 = getelementptr inbounds i32* %P, i32 %A 345f4a2713aSLionel Sambuc %tmp.6 = icmp eq i32* %tmp.4, %P 346f4a2713aSLionel Sambuc %tmp.7 = zext i1 %tmp.6 to i32 347f4a2713aSLionel Sambuc ret i32 %tmp.7 348f4a2713aSLionel Sambuc; CHECK-LABEL: @test20( 349f4a2713aSLionel Sambuc; CHECK: icmp eq i32 %A, 0 350f4a2713aSLionel Sambuc} 351f4a2713aSLionel Sambuc 352f4a2713aSLionel Sambucdefine i32 @test20_as1(i32 addrspace(1)* %P, i32 %A, i32 %B) { 353f4a2713aSLionel Sambuc %tmp.4 = getelementptr inbounds i32 addrspace(1)* %P, i32 %A 354f4a2713aSLionel Sambuc %tmp.6 = icmp eq i32 addrspace(1)* %tmp.4, %P 355f4a2713aSLionel Sambuc %tmp.7 = zext i1 %tmp.6 to i32 356f4a2713aSLionel Sambuc ret i32 %tmp.7 357f4a2713aSLionel Sambuc; CHECK-LABEL: @test20_as1( 358f4a2713aSLionel Sambuc; CHECK: icmp eq i16 %1, 0 359f4a2713aSLionel Sambuc} 360f4a2713aSLionel Sambuc 361f4a2713aSLionel Sambuc 362f4a2713aSLionel Sambucdefine i32 @test21() { 363f4a2713aSLionel Sambuc %pbob1 = alloca %intstruct 364f4a2713aSLionel Sambuc %pbob2 = getelementptr %intstruct* %pbob1 365f4a2713aSLionel Sambuc %pbobel = getelementptr %intstruct* %pbob2, i64 0, i32 0 366f4a2713aSLionel Sambuc %rval = load i32* %pbobel 367f4a2713aSLionel Sambuc ret i32 %rval 368f4a2713aSLionel Sambuc; CHECK-LABEL: @test21( 369f4a2713aSLionel Sambuc; CHECK: getelementptr %intstruct* %pbob1, i64 0, i32 0 370f4a2713aSLionel Sambuc} 371f4a2713aSLionel Sambuc 372f4a2713aSLionel Sambuc 373f4a2713aSLionel Sambuc@A = global i32 1 ; <i32*> [#uses=1] 374f4a2713aSLionel Sambuc@B = global i32 2 ; <i32*> [#uses=1] 375f4a2713aSLionel Sambuc 376f4a2713aSLionel Sambucdefine i1 @test22() { 377f4a2713aSLionel Sambuc %C = icmp ult i32* getelementptr (i32* @A, i64 1), 378f4a2713aSLionel Sambuc getelementptr (i32* @B, i64 2) 379f4a2713aSLionel Sambuc ret i1 %C 380f4a2713aSLionel Sambuc; CHECK-LABEL: @test22( 381f4a2713aSLionel Sambuc; CHECK: icmp ult (i32* getelementptr inbounds (i32* @A, i64 1), i32* getelementptr (i32* @B, i64 2)) 382f4a2713aSLionel Sambuc} 383f4a2713aSLionel Sambuc 384f4a2713aSLionel Sambuc 385f4a2713aSLionel Sambuc%X = type { [10 x i32], float } 386f4a2713aSLionel Sambuc 387f4a2713aSLionel Sambucdefine i1 @test23() { 388f4a2713aSLionel Sambuc %A = getelementptr %X* null, i64 0, i32 0, i64 0 ; <i32*> [#uses=1] 389f4a2713aSLionel Sambuc %B = icmp ne i32* %A, null ; <i1> [#uses=1] 390f4a2713aSLionel Sambuc ret i1 %B 391f4a2713aSLionel Sambuc; CHECK-LABEL: @test23( 392f4a2713aSLionel Sambuc; CHECK: ret i1 false 393f4a2713aSLionel Sambuc} 394f4a2713aSLionel Sambuc 395f4a2713aSLionel Sambucdefine void @test25() { 396f4a2713aSLionel Sambucentry: 397f4a2713aSLionel Sambuc %tmp = getelementptr { i64, i64, i64, i64 }* null, i32 0, i32 3 ; <i64*> [#uses=1] 398f4a2713aSLionel Sambuc %tmp.upgrd.1 = load i64* %tmp ; <i64> [#uses=1] 399f4a2713aSLionel Sambuc %tmp8.ui = load i64* null ; <i64> [#uses=1] 400f4a2713aSLionel Sambuc %tmp8 = bitcast i64 %tmp8.ui to i64 ; <i64> [#uses=1] 401f4a2713aSLionel Sambuc %tmp9 = and i64 %tmp8, %tmp.upgrd.1 ; <i64> [#uses=1] 402f4a2713aSLionel Sambuc %sext = trunc i64 %tmp9 to i32 ; <i32> [#uses=1] 403f4a2713aSLionel Sambuc %tmp27.i = sext i32 %sext to i64 ; <i64> [#uses=1] 404f4a2713aSLionel Sambuc tail call void @foo25( i32 0, i64 %tmp27.i ) 405f4a2713aSLionel Sambuc unreachable 406f4a2713aSLionel Sambuc; CHECK-LABEL: @test25( 407f4a2713aSLionel Sambuc} 408f4a2713aSLionel Sambuc 409f4a2713aSLionel Sambucdeclare void @foo25(i32, i64) 410f4a2713aSLionel Sambuc 411f4a2713aSLionel Sambuc 412f4a2713aSLionel Sambuc; PR1637 413f4a2713aSLionel Sambucdefine i1 @test26(i8* %arr) { 414f4a2713aSLionel Sambuc %X = getelementptr i8* %arr, i32 1 415f4a2713aSLionel Sambuc %Y = getelementptr i8* %arr, i32 1 416f4a2713aSLionel Sambuc %test = icmp uge i8* %X, %Y 417f4a2713aSLionel Sambuc ret i1 %test 418f4a2713aSLionel Sambuc; CHECK-LABEL: @test26( 419f4a2713aSLionel Sambuc; CHECK: ret i1 true 420f4a2713aSLionel Sambuc} 421f4a2713aSLionel Sambuc 422f4a2713aSLionel Sambuc %struct.__large_struct = type { [100 x i64] } 423f4a2713aSLionel Sambuc %struct.compat_siginfo = type { i32, i32, i32, { [29 x i32] } } 424f4a2713aSLionel Sambuc %struct.siginfo_t = type { i32, i32, i32, { { i32, i32, [0 x i8], %struct.sigval_t, i32 }, [88 x i8] } } 425f4a2713aSLionel Sambuc %struct.sigval_t = type { i8* } 426f4a2713aSLionel Sambuc 427f4a2713aSLionel Sambucdefine i32 @test27(%struct.compat_siginfo* %to, %struct.siginfo_t* %from) { 428f4a2713aSLionel Sambucentry: 429f4a2713aSLionel Sambuc %from_addr = alloca %struct.siginfo_t* 430f4a2713aSLionel Sambuc %tmp344 = load %struct.siginfo_t** %from_addr, align 8 431f4a2713aSLionel Sambuc %tmp345 = getelementptr %struct.siginfo_t* %tmp344, i32 0, i32 3 432f4a2713aSLionel Sambuc %tmp346 = getelementptr { { i32, i32, [0 x i8], %struct.sigval_t, i32 }, [88 x i8] }* %tmp345, i32 0, i32 0 433f4a2713aSLionel Sambuc %tmp346347 = bitcast { i32, i32, [0 x i8], %struct.sigval_t, i32 }* %tmp346 to { i32, i32, %struct.sigval_t }* 434f4a2713aSLionel Sambuc %tmp348 = getelementptr { i32, i32, %struct.sigval_t }* %tmp346347, i32 0, i32 2 435f4a2713aSLionel Sambuc %tmp349 = getelementptr %struct.sigval_t* %tmp348, i32 0, i32 0 436f4a2713aSLionel Sambuc %tmp349350 = bitcast i8** %tmp349 to i32* 437f4a2713aSLionel Sambuc %tmp351 = load i32* %tmp349350, align 8 438f4a2713aSLionel Sambuc %tmp360 = call i32 asm sideeffect "...", 439f4a2713aSLionel Sambuc "=r,ir,*m,i,0,~{dirflag},~{fpsr},~{flags}"( i32 %tmp351, 440f4a2713aSLionel Sambuc %struct.__large_struct* null, i32 -14, i32 0 ) 441f4a2713aSLionel Sambuc unreachable 442f4a2713aSLionel Sambuc; CHECK-LABEL: @test27( 443f4a2713aSLionel Sambuc} 444f4a2713aSLionel Sambuc 445f4a2713aSLionel Sambuc; PR1978 446f4a2713aSLionel Sambuc %struct.x = type <{ i8 }> 447f4a2713aSLionel Sambuc@.str = internal constant [6 x i8] c"Main!\00" 448f4a2713aSLionel Sambuc@.str1 = internal constant [12 x i8] c"destroy %p\0A\00" 449f4a2713aSLionel Sambuc 450f4a2713aSLionel Sambucdefine i32 @test28() nounwind { 451f4a2713aSLionel Sambucentry: 452f4a2713aSLionel Sambuc %orientations = alloca [1 x [1 x %struct.x]] 453f4a2713aSLionel Sambuc %tmp3 = call i32 @puts( i8* getelementptr ([6 x i8]* @.str, i32 0, i32 0) ) nounwind 454f4a2713aSLionel Sambuc %tmp45 = getelementptr inbounds [1 x [1 x %struct.x]]* %orientations, i32 1, i32 0, i32 0 455f4a2713aSLionel Sambuc %orientations62 = getelementptr [1 x [1 x %struct.x]]* %orientations, i32 0, i32 0, i32 0 456f4a2713aSLionel Sambuc br label %bb10 457f4a2713aSLionel Sambuc 458f4a2713aSLionel Sambucbb10: 459f4a2713aSLionel Sambuc %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %bb10 ] 460f4a2713aSLionel Sambuc %tmp.0.reg2mem.0.rec = mul i32 %indvar, -1 461f4a2713aSLionel Sambuc %tmp12.rec = add i32 %tmp.0.reg2mem.0.rec, -1 462f4a2713aSLionel Sambuc %tmp12 = getelementptr inbounds %struct.x* %tmp45, i32 %tmp12.rec 463f4a2713aSLionel Sambuc %tmp16 = call i32 (i8*, ...)* @printf( i8* getelementptr ([12 x i8]* @.str1, i32 0, i32 0), %struct.x* %tmp12 ) nounwind 464f4a2713aSLionel Sambuc %tmp84 = icmp eq %struct.x* %tmp12, %orientations62 465f4a2713aSLionel Sambuc %indvar.next = add i32 %indvar, 1 466f4a2713aSLionel Sambuc br i1 %tmp84, label %bb17, label %bb10 467f4a2713aSLionel Sambuc 468f4a2713aSLionel Sambucbb17: 469f4a2713aSLionel Sambuc ret i32 0 470f4a2713aSLionel Sambuc; CHECK-LABEL: @test28( 471f4a2713aSLionel Sambuc; CHECK: icmp eq i32 %indvar, 0 472f4a2713aSLionel Sambuc} 473f4a2713aSLionel Sambuc 474f4a2713aSLionel Sambucdeclare i32 @puts(i8*) 475f4a2713aSLionel Sambuc 476f4a2713aSLionel Sambucdeclare i32 @printf(i8*, ...) 477f4a2713aSLionel Sambuc 478f4a2713aSLionel Sambuc 479f4a2713aSLionel Sambuc 480f4a2713aSLionel Sambuc 481f4a2713aSLionel Sambuc; rdar://6762290 482f4a2713aSLionel Sambuc %T = type <{ i64, i64, i64 }> 483f4a2713aSLionel Sambucdefine i32 @test29(i8* %start, i32 %X) nounwind { 484f4a2713aSLionel Sambucentry: 485f4a2713aSLionel Sambuc %tmp3 = load i64* null 486f4a2713aSLionel Sambuc %add.ptr = getelementptr i8* %start, i64 %tmp3 487f4a2713aSLionel Sambuc %tmp158 = load i32* null 488f4a2713aSLionel Sambuc %add.ptr159 = getelementptr %T* null, i32 %tmp158 489f4a2713aSLionel Sambuc %add.ptr209 = getelementptr i8* %start, i64 0 490f4a2713aSLionel Sambuc %add.ptr212 = getelementptr i8* %add.ptr209, i32 %X 491f4a2713aSLionel Sambuc %cmp214 = icmp ugt i8* %add.ptr212, %add.ptr 492f4a2713aSLionel Sambuc br i1 %cmp214, label %if.then216, label %if.end363 493f4a2713aSLionel Sambuc 494f4a2713aSLionel Sambucif.then216: 495f4a2713aSLionel Sambuc ret i32 1 496f4a2713aSLionel Sambuc 497f4a2713aSLionel Sambucif.end363: 498f4a2713aSLionel Sambuc ret i32 0 499f4a2713aSLionel Sambuc; CHECK-LABEL: @test29( 500f4a2713aSLionel Sambuc} 501f4a2713aSLionel Sambuc 502f4a2713aSLionel Sambuc 503f4a2713aSLionel Sambuc; PR3694 504f4a2713aSLionel Sambucdefine i32 @test30(i32 %m, i32 %n) nounwind { 505f4a2713aSLionel Sambucentry: 506f4a2713aSLionel Sambuc %0 = alloca i32, i32 %n, align 4 507f4a2713aSLionel Sambuc %1 = bitcast i32* %0 to [0 x i32]* 508f4a2713aSLionel Sambuc call void @test30f(i32* %0) nounwind 509f4a2713aSLionel Sambuc %2 = getelementptr [0 x i32]* %1, i32 0, i32 %m 510f4a2713aSLionel Sambuc %3 = load i32* %2, align 4 511f4a2713aSLionel Sambuc ret i32 %3 512f4a2713aSLionel Sambuc; CHECK-LABEL: @test30( 513f4a2713aSLionel Sambuc; CHECK: getelementptr i32 514f4a2713aSLionel Sambuc} 515f4a2713aSLionel Sambuc 516f4a2713aSLionel Sambucdeclare void @test30f(i32*) 517f4a2713aSLionel Sambuc 518f4a2713aSLionel Sambuc 519f4a2713aSLionel Sambuc 520f4a2713aSLionel Sambucdefine i1 @test31(i32* %A) { 521f4a2713aSLionel Sambuc %B = getelementptr i32* %A, i32 1 522f4a2713aSLionel Sambuc %C = getelementptr i32* %A, i64 1 523f4a2713aSLionel Sambuc %V = icmp eq i32* %B, %C 524f4a2713aSLionel Sambuc ret i1 %V 525f4a2713aSLionel Sambuc; CHECK-LABEL: @test31( 526f4a2713aSLionel Sambuc; CHECK: ret i1 true 527f4a2713aSLionel Sambuc} 528f4a2713aSLionel Sambuc 529f4a2713aSLionel Sambuc 530f4a2713aSLionel Sambuc; PR1345 531f4a2713aSLionel Sambucdefine i8* @test32(i8* %v) { 532f4a2713aSLionel Sambuc %A = alloca [4 x i8*], align 16 533f4a2713aSLionel Sambuc %B = getelementptr [4 x i8*]* %A, i32 0, i32 0 534f4a2713aSLionel Sambuc store i8* null, i8** %B 535f4a2713aSLionel Sambuc %C = bitcast [4 x i8*]* %A to { [16 x i8] }* 536f4a2713aSLionel Sambuc %D = getelementptr { [16 x i8] }* %C, i32 0, i32 0, i32 8 537f4a2713aSLionel Sambuc %E = bitcast i8* %D to i8** 538f4a2713aSLionel Sambuc store i8* %v, i8** %E 539f4a2713aSLionel Sambuc %F = getelementptr [4 x i8*]* %A, i32 0, i32 2 540f4a2713aSLionel Sambuc %G = load i8** %F 541f4a2713aSLionel Sambuc ret i8* %G 542f4a2713aSLionel Sambuc; CHECK-LABEL: @test32( 543f4a2713aSLionel Sambuc; CHECK: %D = getelementptr [4 x i8*]* %A, i64 0, i64 1 544f4a2713aSLionel Sambuc; CHECK: %F = getelementptr [4 x i8*]* %A, i64 0, i64 2 545f4a2713aSLionel Sambuc} 546f4a2713aSLionel Sambuc 547f4a2713aSLionel Sambuc; PR3290 548f4a2713aSLionel Sambuc%struct.Key = type { { i32, i32 } } 549f4a2713aSLionel Sambuc%struct.anon = type <{ i8, [3 x i8], i32 }> 550f4a2713aSLionel Sambuc 551f4a2713aSLionel Sambucdefine i32* @test33(%struct.Key* %A) { 552f4a2713aSLionel Sambuc; CHECK-LABEL: @test33( 553f4a2713aSLionel Sambuc; CHECK: getelementptr %struct.Key* %A, i64 0, i32 0, i32 1 554f4a2713aSLionel Sambuc %B = bitcast %struct.Key* %A to %struct.anon* 555f4a2713aSLionel Sambuc %C = getelementptr %struct.anon* %B, i32 0, i32 2 556f4a2713aSLionel Sambuc ret i32* %C 557f4a2713aSLionel Sambuc} 558f4a2713aSLionel Sambuc 559f4a2713aSLionel Sambucdefine i32 addrspace(1)* @test33_as1(%struct.Key addrspace(1)* %A) { 560f4a2713aSLionel Sambuc; CHECK-LABEL: @test33_as1( 561f4a2713aSLionel Sambuc; CHECK: getelementptr %struct.Key addrspace(1)* %A, i16 0, i32 0, i32 1 562f4a2713aSLionel Sambuc %B = bitcast %struct.Key addrspace(1)* %A to %struct.anon addrspace(1)* 563f4a2713aSLionel Sambuc %C = getelementptr %struct.anon addrspace(1)* %B, i32 0, i32 2 564f4a2713aSLionel Sambuc ret i32 addrspace(1)* %C 565f4a2713aSLionel Sambuc} 566f4a2713aSLionel Sambuc 567f4a2713aSLionel Sambucdefine i32 addrspace(1)* @test33_array_as1([10 x i32] addrspace(1)* %A) { 568f4a2713aSLionel Sambuc; CHECK-LABEL: @test33_array_as1( 569f4a2713aSLionel Sambuc; CHECK: getelementptr [10 x i32] addrspace(1)* %A, i16 0, i16 2 570f4a2713aSLionel Sambuc %B = bitcast [10 x i32] addrspace(1)* %A to [5 x i32] addrspace(1)* 571f4a2713aSLionel Sambuc %C = getelementptr [5 x i32] addrspace(1)* %B, i32 0, i32 2 572f4a2713aSLionel Sambuc ret i32 addrspace(1)* %C 573f4a2713aSLionel Sambuc} 574f4a2713aSLionel Sambuc 575f4a2713aSLionel Sambuc; Make sure the GEP indices use the right pointer sized integer 576f4a2713aSLionel Sambucdefine i32 addrspace(1)* @test33_array_struct_as1([10 x %struct.Key] addrspace(1)* %A) { 577f4a2713aSLionel Sambuc; CHECK-LABEL: @test33_array_struct_as1( 578f4a2713aSLionel Sambuc; CHECK: getelementptr [10 x %struct.Key] addrspace(1)* %A, i16 0, i16 1, i32 0, i32 0 579f4a2713aSLionel Sambuc %B = bitcast [10 x %struct.Key] addrspace(1)* %A to [20 x i32] addrspace(1)* 580f4a2713aSLionel Sambuc %C = getelementptr [20 x i32] addrspace(1)* %B, i32 0, i32 2 581f4a2713aSLionel Sambuc ret i32 addrspace(1)* %C 582f4a2713aSLionel Sambuc} 583f4a2713aSLionel Sambuc 584*0a6a1f1dSLionel Sambucdefine i32 addrspace(1)* @test33_addrspacecast(%struct.Key* %A) { 585*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @test33_addrspacecast( 586*0a6a1f1dSLionel Sambuc; CHECK: %C = getelementptr %struct.Key* %A, i64 0, i32 0, i32 1 587*0a6a1f1dSLionel Sambuc; CHECK-NEXT: addrspacecast i32* %C to i32 addrspace(1)* 588*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ret 589*0a6a1f1dSLionel Sambuc %B = addrspacecast %struct.Key* %A to %struct.anon addrspace(1)* 590*0a6a1f1dSLionel Sambuc %C = getelementptr %struct.anon addrspace(1)* %B, i32 0, i32 2 591*0a6a1f1dSLionel Sambuc ret i32 addrspace(1)* %C 592*0a6a1f1dSLionel Sambuc} 593*0a6a1f1dSLionel Sambuc 594f4a2713aSLionel Sambuc %T2 = type { i8*, i8 } 595f4a2713aSLionel Sambucdefine i8* @test34(i8* %Val, i64 %V) nounwind { 596f4a2713aSLionel Sambucentry: 597f4a2713aSLionel Sambuc %A = alloca %T2, align 8 598f4a2713aSLionel Sambuc %mrv_gep = bitcast %T2* %A to i64* 599f4a2713aSLionel Sambuc %B = getelementptr %T2* %A, i64 0, i32 0 600f4a2713aSLionel Sambuc 601f4a2713aSLionel Sambuc store i64 %V, i64* %mrv_gep 602f4a2713aSLionel Sambuc %C = load i8** %B, align 8 603f4a2713aSLionel Sambuc ret i8* %C 604f4a2713aSLionel Sambuc; CHECK-LABEL: @test34( 605*0a6a1f1dSLionel Sambuc; CHECK: %[[C:.*]] = inttoptr i64 %V to i8* 606*0a6a1f1dSLionel Sambuc; CHECK: ret i8* %[[C]] 607f4a2713aSLionel Sambuc} 608f4a2713aSLionel Sambuc 609f4a2713aSLionel Sambuc%t0 = type { i8*, [19 x i8] } 610f4a2713aSLionel Sambuc%t1 = type { i8*, [0 x i8] } 611f4a2713aSLionel Sambuc 612f4a2713aSLionel Sambuc@array = external global [11 x i8] 613f4a2713aSLionel Sambuc 614f4a2713aSLionel Sambuc@s = external global %t0 615f4a2713aSLionel Sambuc@"\01LC8" = external constant [17 x i8] 616f4a2713aSLionel Sambuc 617f4a2713aSLionel Sambuc; Instcombine should be able to fold this getelementptr. 618f4a2713aSLionel Sambuc 619f4a2713aSLionel Sambucdefine i32 @test35() nounwind { 620f4a2713aSLionel Sambuc call i32 (i8*, ...)* @printf(i8* getelementptr ([17 x i8]* @"\01LC8", i32 0, i32 0), 621f4a2713aSLionel Sambuc i8* getelementptr (%t1* bitcast (%t0* @s to %t1*), i32 0, i32 1, i32 0)) nounwind 622f4a2713aSLionel Sambuc ret i32 0 623f4a2713aSLionel Sambuc; CHECK-LABEL: @test35( 624f4a2713aSLionel Sambuc; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* getelementptr inbounds (%t0* @s, i64 0, i32 1, i64 0)) [[NUW:#[0-9]+]] 625f4a2713aSLionel Sambuc} 626f4a2713aSLionel Sambuc 627f4a2713aSLionel Sambuc; Instcombine should constant-fold the GEP so that indices that have 628f4a2713aSLionel Sambuc; static array extents are within bounds of those array extents. 629f4a2713aSLionel Sambuc; In the below, -1 is not in the range [0,11). After the transformation, 630f4a2713aSLionel Sambuc; the same address is computed, but 3 is in the range of [0,11). 631f4a2713aSLionel Sambuc 632f4a2713aSLionel Sambucdefine i8* @test36() nounwind { 633f4a2713aSLionel Sambuc ret i8* getelementptr ([11 x i8]* @array, i32 0, i64 -1) 634f4a2713aSLionel Sambuc; CHECK-LABEL: @test36( 635f4a2713aSLionel Sambuc; CHECK: ret i8* getelementptr ([11 x i8]* @array, i64 1676976733973595601, i64 4) 636f4a2713aSLionel Sambuc} 637f4a2713aSLionel Sambuc 638f4a2713aSLionel Sambuc; Instcombine shouldn't assume that gep(A,0,1) != gep(A,1,0). 639f4a2713aSLionel Sambuc@A37 = external constant [1 x i8] 640f4a2713aSLionel Sambucdefine i1 @test37() nounwind { 641f4a2713aSLionel Sambuc; CHECK-LABEL: @test37( 642f4a2713aSLionel Sambuc; CHECK: ret i1 true 643f4a2713aSLionel Sambuc %t = icmp eq i8* getelementptr ([1 x i8]* @A37, i64 0, i64 1), 644f4a2713aSLionel Sambuc getelementptr ([1 x i8]* @A37, i64 1, i64 0) 645f4a2713aSLionel Sambuc ret i1 %t 646f4a2713aSLionel Sambuc} 647f4a2713aSLionel Sambuc 648f4a2713aSLionel Sambuc; Test index promotion 649f4a2713aSLionel Sambucdefine i32* @test38(i32* %I, i32 %n) { 650f4a2713aSLionel Sambuc %A = getelementptr i32* %I, i32 %n 651f4a2713aSLionel Sambuc ret i32* %A 652f4a2713aSLionel Sambuc; CHECK-LABEL: @test38( 653f4a2713aSLionel Sambuc; CHECK: = sext i32 %n to i64 654f4a2713aSLionel Sambuc; CHECK: %A = getelementptr i32* %I, i64 % 655f4a2713aSLionel Sambuc} 656f4a2713aSLionel Sambuc 657f4a2713aSLionel Sambuc; Test that we don't duplicate work when the second gep is a "bitcast". 658f4a2713aSLionel Sambuc%pr10322_t = type { i8* } 659f4a2713aSLionel Sambucdeclare void @pr10322_f2(%pr10322_t*) 660f4a2713aSLionel Sambucdeclare void @pr10322_f3(i8**) 661f4a2713aSLionel Sambucdefine void @pr10322_f1(%pr10322_t* %foo) { 662f4a2713aSLionel Sambucentry: 663f4a2713aSLionel Sambuc %arrayidx8 = getelementptr inbounds %pr10322_t* %foo, i64 2 664f4a2713aSLionel Sambuc call void @pr10322_f2(%pr10322_t* %arrayidx8) nounwind 665f4a2713aSLionel Sambuc %tmp2 = getelementptr inbounds %pr10322_t* %arrayidx8, i64 0, i32 0 666f4a2713aSLionel Sambuc call void @pr10322_f3(i8** %tmp2) nounwind 667f4a2713aSLionel Sambuc ret void 668f4a2713aSLionel Sambuc 669f4a2713aSLionel Sambuc; CHECK-LABEL: @pr10322_f1( 670f4a2713aSLionel Sambuc; CHECK: %tmp2 = getelementptr inbounds %pr10322_t* %arrayidx8, i64 0, i32 0 671f4a2713aSLionel Sambuc} 672f4a2713aSLionel Sambuc 673f4a2713aSLionel Sambuc; Test that we combine the last two geps in this sequence, before we 674f4a2713aSLionel Sambuc; would wait for gep1 and gep2 to be combined and never combine 2 and 3. 675f4a2713aSLionel Sambuc%three_gep_t = type {i32} 676f4a2713aSLionel Sambuc%three_gep_t2 = type {%three_gep_t} 677f4a2713aSLionel Sambuc 678f4a2713aSLionel Sambucdefine void @three_gep_f(%three_gep_t2* %x) { 679f4a2713aSLionel Sambuc %gep1 = getelementptr %three_gep_t2* %x, i64 2 680f4a2713aSLionel Sambuc call void @three_gep_h(%three_gep_t2* %gep1) 681f4a2713aSLionel Sambuc %gep2 = getelementptr %three_gep_t2* %gep1, i64 0, i32 0 682f4a2713aSLionel Sambuc %gep3 = getelementptr %three_gep_t* %gep2, i64 0, i32 0 683f4a2713aSLionel Sambuc call void @three_gep_g(i32* %gep3) 684f4a2713aSLionel Sambuc 685f4a2713aSLionel Sambuc; CHECK-LABEL: @three_gep_f( 686f4a2713aSLionel Sambuc; CHECK: %gep3 = getelementptr %three_gep_t2* %gep1, i64 0, i32 0, i32 0 687f4a2713aSLionel Sambuc ret void 688f4a2713aSLionel Sambuc} 689f4a2713aSLionel Sambuc 690f4a2713aSLionel Sambucdeclare void @three_gep_g(i32*) 691f4a2713aSLionel Sambucdeclare void @three_gep_h(%three_gep_t2*) 692f4a2713aSLionel Sambuc 693f4a2713aSLionel Sambuc%struct.ham = type { i32, %struct.zot*, %struct.zot*, %struct.zot* } 694f4a2713aSLionel Sambuc%struct.zot = type { i64, i8 } 695f4a2713aSLionel Sambuc 696f4a2713aSLionel Sambucdefine void @test39(%struct.ham* %arg, i8 %arg1) nounwind { 697f4a2713aSLionel Sambuc %tmp = getelementptr inbounds %struct.ham* %arg, i64 0, i32 2 698f4a2713aSLionel Sambuc %tmp2 = load %struct.zot** %tmp, align 8 699f4a2713aSLionel Sambuc %tmp3 = bitcast %struct.zot* %tmp2 to i8* 700f4a2713aSLionel Sambuc %tmp4 = getelementptr inbounds i8* %tmp3, i64 -8 701f4a2713aSLionel Sambuc store i8 %arg1, i8* %tmp4, align 8 702f4a2713aSLionel Sambuc ret void 703f4a2713aSLionel Sambuc 704f4a2713aSLionel Sambuc; CHECK-LABEL: @test39( 705f4a2713aSLionel Sambuc; CHECK: getelementptr inbounds %struct.ham* %arg, i64 0, i32 2 706*0a6a1f1dSLionel Sambuc; CHECK: getelementptr inbounds i8* %{{.+}}, i64 -8 707f4a2713aSLionel Sambuc} 708f4a2713aSLionel Sambuc 709f4a2713aSLionel Sambucdefine i1 @pr16483([1 x i8]* %a, [1 x i8]* %b) { 710f4a2713aSLionel Sambuc %c = getelementptr [1 x i8]* %a, i32 0, i32 0 711f4a2713aSLionel Sambuc %d = getelementptr [1 x i8]* %b, i32 0, i32 0 712f4a2713aSLionel Sambuc %cmp = icmp ult i8* %c, %d 713f4a2713aSLionel Sambuc ret i1 %cmp 714f4a2713aSLionel Sambuc 715f4a2713aSLionel Sambuc; CHECK-LABEL: @pr16483( 716f4a2713aSLionel Sambuc; CHECK-NEXT: icmp ult [1 x i8]* %a, %b 717f4a2713aSLionel Sambuc} 718f4a2713aSLionel Sambuc 719f4a2713aSLionel Sambucdefine i8 @test_gep_bitcast_as1(i32 addrspace(1)* %arr, i16 %N) { 720f4a2713aSLionel Sambuc; CHECK-LABEL: @test_gep_bitcast_as1( 721f4a2713aSLionel Sambuc; CHECK: getelementptr i32 addrspace(1)* %arr, i16 %N 722f4a2713aSLionel Sambuc; CHECK: bitcast 723f4a2713aSLionel Sambuc %cast = bitcast i32 addrspace(1)* %arr to i8 addrspace(1)* 724f4a2713aSLionel Sambuc %V = mul i16 %N, 4 725f4a2713aSLionel Sambuc %t = getelementptr i8 addrspace(1)* %cast, i16 %V 726f4a2713aSLionel Sambuc %x = load i8 addrspace(1)* %t 727f4a2713aSLionel Sambuc ret i8 %x 728f4a2713aSLionel Sambuc} 729f4a2713aSLionel Sambuc 730f4a2713aSLionel Sambuc; The element size of the array matches the element size of the pointer 731f4a2713aSLionel Sambucdefine i64 @test_gep_bitcast_array_same_size_element([100 x double]* %arr, i64 %N) { 732f4a2713aSLionel Sambuc; CHECK-LABEL: @test_gep_bitcast_array_same_size_element( 733f4a2713aSLionel Sambuc; CHECK: getelementptr [100 x double]* %arr, i64 0, i64 %V 734f4a2713aSLionel Sambuc; CHECK: bitcast 735f4a2713aSLionel Sambuc %cast = bitcast [100 x double]* %arr to i64* 736f4a2713aSLionel Sambuc %V = mul i64 %N, 8 737f4a2713aSLionel Sambuc %t = getelementptr i64* %cast, i64 %V 738f4a2713aSLionel Sambuc %x = load i64* %t 739f4a2713aSLionel Sambuc ret i64 %x 740f4a2713aSLionel Sambuc} 741f4a2713aSLionel Sambuc 742*0a6a1f1dSLionel Sambuc; gep should be done in the original address space. 743*0a6a1f1dSLionel Sambucdefine i64 @test_gep_bitcast_array_same_size_element_addrspacecast([100 x double]* %arr, i64 %N) { 744*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @test_gep_bitcast_array_same_size_element_addrspacecast( 745*0a6a1f1dSLionel Sambuc; CHECK: getelementptr [100 x double]* %arr, i64 0, i64 %V 746*0a6a1f1dSLionel Sambuc; CHECK-NEXT: bitcast double* 747*0a6a1f1dSLionel Sambuc; CHECK-NEXT: %t = addrspacecast i64* 748*0a6a1f1dSLionel Sambuc; CHECK: load i64 addrspace(3)* %t 749*0a6a1f1dSLionel Sambuc %cast = addrspacecast [100 x double]* %arr to i64 addrspace(3)* 750*0a6a1f1dSLionel Sambuc %V = mul i64 %N, 8 751*0a6a1f1dSLionel Sambuc %t = getelementptr i64 addrspace(3)* %cast, i64 %V 752*0a6a1f1dSLionel Sambuc %x = load i64 addrspace(3)* %t 753*0a6a1f1dSLionel Sambuc ret i64 %x 754*0a6a1f1dSLionel Sambuc} 755*0a6a1f1dSLionel Sambuc 756f4a2713aSLionel Sambuc; The element size of the array is different the element size of the pointer 757f4a2713aSLionel Sambucdefine i8 @test_gep_bitcast_array_different_size_element([100 x double]* %arr, i64 %N) { 758f4a2713aSLionel Sambuc; CHECK-LABEL: @test_gep_bitcast_array_different_size_element( 759f4a2713aSLionel Sambuc; CHECK: getelementptr [100 x double]* %arr, i64 0, i64 %N 760f4a2713aSLionel Sambuc; CHECK: bitcast 761f4a2713aSLionel Sambuc %cast = bitcast [100 x double]* %arr to i8* 762f4a2713aSLionel Sambuc %V = mul i64 %N, 8 763f4a2713aSLionel Sambuc %t = getelementptr i8* %cast, i64 %V 764f4a2713aSLionel Sambuc %x = load i8* %t 765f4a2713aSLionel Sambuc ret i8 %x 766f4a2713aSLionel Sambuc} 767f4a2713aSLionel Sambuc 768f4a2713aSLionel Sambucdefine i64 @test_gep_bitcast_array_same_size_element_as1([100 x double] addrspace(1)* %arr, i16 %N) { 769f4a2713aSLionel Sambuc; CHECK-LABEL: @test_gep_bitcast_array_same_size_element_as1( 770f4a2713aSLionel Sambuc; CHECK: getelementptr [100 x double] addrspace(1)* %arr, i16 0, i16 %V 771f4a2713aSLionel Sambuc; CHECK: bitcast 772f4a2713aSLionel Sambuc %cast = bitcast [100 x double] addrspace(1)* %arr to i64 addrspace(1)* 773f4a2713aSLionel Sambuc %V = mul i16 %N, 8 774f4a2713aSLionel Sambuc %t = getelementptr i64 addrspace(1)* %cast, i16 %V 775f4a2713aSLionel Sambuc %x = load i64 addrspace(1)* %t 776f4a2713aSLionel Sambuc ret i64 %x 777f4a2713aSLionel Sambuc} 778f4a2713aSLionel Sambuc 779f4a2713aSLionel Sambucdefine i8 @test_gep_bitcast_array_different_size_element_as1([100 x double] addrspace(1)* %arr, i16 %N) { 780f4a2713aSLionel Sambuc; CHECK-LABEL: @test_gep_bitcast_array_different_size_element_as1( 781f4a2713aSLionel Sambuc; CHECK: getelementptr [100 x double] addrspace(1)* %arr, i16 0, i16 %N 782f4a2713aSLionel Sambuc; CHECK: bitcast 783f4a2713aSLionel Sambuc %cast = bitcast [100 x double] addrspace(1)* %arr to i8 addrspace(1)* 784f4a2713aSLionel Sambuc %V = mul i16 %N, 8 785f4a2713aSLionel Sambuc %t = getelementptr i8 addrspace(1)* %cast, i16 %V 786f4a2713aSLionel Sambuc %x = load i8 addrspace(1)* %t 787f4a2713aSLionel Sambuc ret i8 %x 788f4a2713aSLionel Sambuc} 789f4a2713aSLionel Sambuc 790f4a2713aSLionel Sambucdefine i64 @test40() { 791f4a2713aSLionel Sambuc %array = alloca [3 x i32], align 4 792f4a2713aSLionel Sambuc %gep = getelementptr inbounds [3 x i32]* %array, i64 0, i64 2 793f4a2713aSLionel Sambuc %gepi8 = bitcast i32* %gep to i8* 794f4a2713aSLionel Sambuc %p = ptrtoint [3 x i32]* %array to i64 795f4a2713aSLionel Sambuc %np = sub i64 0, %p 796f4a2713aSLionel Sambuc %gep2 = getelementptr i8* %gepi8, i64 %np 797f4a2713aSLionel Sambuc %ret = ptrtoint i8* %gep2 to i64 798f4a2713aSLionel Sambuc ret i64 %ret 799f4a2713aSLionel Sambuc 800f4a2713aSLionel Sambuc; CHECK-LABEL: @test40 801f4a2713aSLionel Sambuc; CHECK-NEXT: ret i64 8 802f4a2713aSLionel Sambuc} 803f4a2713aSLionel Sambuc 804f4a2713aSLionel Sambucdefine i16 @test41([3 x i32] addrspace(1)* %array) { 805f4a2713aSLionel Sambuc %gep = getelementptr inbounds [3 x i32] addrspace(1)* %array, i16 0, i16 2 806f4a2713aSLionel Sambuc %gepi8 = bitcast i32 addrspace(1)* %gep to i8 addrspace(1)* 807f4a2713aSLionel Sambuc %p = ptrtoint [3 x i32] addrspace(1)* %array to i16 808f4a2713aSLionel Sambuc %np = sub i16 0, %p 809f4a2713aSLionel Sambuc %gep2 = getelementptr i8 addrspace(1)* %gepi8, i16 %np 810f4a2713aSLionel Sambuc %ret = ptrtoint i8 addrspace(1)* %gep2 to i16 811f4a2713aSLionel Sambuc ret i16 %ret 812f4a2713aSLionel Sambuc 813f4a2713aSLionel Sambuc; CHECK-LABEL: @test41( 814f4a2713aSLionel Sambuc; CHECK-NEXT: ret i16 8 815f4a2713aSLionel Sambuc} 816f4a2713aSLionel Sambuc 817*0a6a1f1dSLionel Sambucdefine i8* @test42(i8* %c1, i8* %c2) { 818*0a6a1f1dSLionel Sambuc %ptrtoint = ptrtoint i8* %c1 to i64 819*0a6a1f1dSLionel Sambuc %sub = sub i64 0, %ptrtoint 820*0a6a1f1dSLionel Sambuc %gep = getelementptr inbounds i8* %c2, i64 %sub 821*0a6a1f1dSLionel Sambuc ret i8* %gep 822*0a6a1f1dSLionel Sambuc 823*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @test42( 824*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[PTRTOINT1:%.*]] = ptrtoint i8* %c1 to i64 825*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[PTRTOINT2:%.*]] = ptrtoint i8* %c2 to i64 826*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[PTRTOINT2]], [[PTRTOINT1]] 827*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[INTTOPTR:%.*]] = inttoptr i64 [[SUB]] to i8* 828*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ret i8* [[INTTOPTR]] 829*0a6a1f1dSLionel Sambuc} 830*0a6a1f1dSLionel Sambuc 831*0a6a1f1dSLionel Sambucdefine i16* @test43(i16* %c1, i16* %c2) { 832*0a6a1f1dSLionel Sambuc %ptrtoint = ptrtoint i16* %c1 to i64 833*0a6a1f1dSLionel Sambuc %sub = sub i64 0, %ptrtoint 834*0a6a1f1dSLionel Sambuc %shr = ashr i64 %sub, 1 835*0a6a1f1dSLionel Sambuc %gep = getelementptr inbounds i16* %c2, i64 %shr 836*0a6a1f1dSLionel Sambuc ret i16* %gep 837*0a6a1f1dSLionel Sambuc 838*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @test43( 839*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[PTRTOINT1:%.*]] = ptrtoint i16* %c1 to i64 840*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[PTRTOINT2:%.*]] = ptrtoint i16* %c2 to i64 841*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[PTRTOINT2]], [[PTRTOINT1]] 842*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[INTTOPTR:%.*]] = inttoptr i64 [[SUB]] to i16* 843*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ret i16* [[INTTOPTR]] 844*0a6a1f1dSLionel Sambuc} 845*0a6a1f1dSLionel Sambuc 846*0a6a1f1dSLionel Sambucdefine %struct.C* @test44(%struct.C* %c1, %struct.C* %c2) { 847*0a6a1f1dSLionel Sambuc %ptrtoint = ptrtoint %struct.C* %c1 to i64 848*0a6a1f1dSLionel Sambuc %sub = sub i64 0, %ptrtoint 849*0a6a1f1dSLionel Sambuc %shr = sdiv i64 %sub, 7 850*0a6a1f1dSLionel Sambuc %gep = getelementptr inbounds %struct.C* %c2, i64 %shr 851*0a6a1f1dSLionel Sambuc ret %struct.C* %gep 852*0a6a1f1dSLionel Sambuc 853*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @test44( 854*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[PTRTOINT1:%.*]] = ptrtoint %struct.C* %c1 to i64 855*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[PTRTOINT2:%.*]] = ptrtoint %struct.C* %c2 to i64 856*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[PTRTOINT2]], [[PTRTOINT1]] 857*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[INTTOPTR:%.*]] = inttoptr i64 [[SUB]] to %struct.C* 858*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ret %struct.C* [[INTTOPTR]] 859*0a6a1f1dSLionel Sambuc} 860*0a6a1f1dSLionel Sambuc 861*0a6a1f1dSLionel Sambucdefine %struct.C* @test45(%struct.C* %c1, %struct.C** %c2) { 862*0a6a1f1dSLionel Sambuc %ptrtoint1 = ptrtoint %struct.C* %c1 to i64 863*0a6a1f1dSLionel Sambuc %ptrtoint2 = ptrtoint %struct.C** %c2 to i64 864*0a6a1f1dSLionel Sambuc %sub = sub i64 %ptrtoint2, %ptrtoint1 ; C2 - C1 865*0a6a1f1dSLionel Sambuc %shr = sdiv i64 %sub, 7 866*0a6a1f1dSLionel Sambuc %gep = getelementptr inbounds %struct.C* %c1, i64 %shr ; C1 + (C2 - C1) 867*0a6a1f1dSLionel Sambuc ret %struct.C* %gep 868*0a6a1f1dSLionel Sambuc 869*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @test45( 870*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[BITCAST:%.*]] = bitcast %struct.C** %c2 to %struct.C* 871*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ret %struct.C* [[BITCAST]] 872*0a6a1f1dSLionel Sambuc} 873*0a6a1f1dSLionel Sambuc 874*0a6a1f1dSLionel Sambucdefine %struct.C* @test46(%struct.C* %c1, %struct.C* %c2, i64 %N) { 875*0a6a1f1dSLionel Sambuc %ptrtoint = ptrtoint %struct.C* %c1 to i64 876*0a6a1f1dSLionel Sambuc %sub = sub i64 0, %ptrtoint 877*0a6a1f1dSLionel Sambuc %sdiv = sdiv i64 %sub, %N 878*0a6a1f1dSLionel Sambuc %gep = getelementptr inbounds %struct.C* %c2, i64 %sdiv 879*0a6a1f1dSLionel Sambuc ret %struct.C* %gep 880*0a6a1f1dSLionel Sambuc 881*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @test46( 882*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[PTRTOINT:%.*]] = ptrtoint %struct.C* %c1 to i64 883*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[SUB:%.*]] = sub i64 0, [[PTRTOINT]] 884*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[SDIV:%.*]] = sdiv i64 [[SUB]], %N 885*0a6a1f1dSLionel Sambuc; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds %struct.C* %c2, i64 %sdiv 886*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ret %struct.C* [[GEP]] 887*0a6a1f1dSLionel Sambuc} 888*0a6a1f1dSLionel Sambuc 889*0a6a1f1dSLionel Sambucdefine i32 addrspace(1)* @ascast_0_gep(i32* %p) nounwind { 890*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @ascast_0_gep( 891*0a6a1f1dSLionel Sambuc; CHECK-NOT: getelementptr 892*0a6a1f1dSLionel Sambuc; CHECK: ret 893*0a6a1f1dSLionel Sambuc %gep = getelementptr i32* %p, i32 0 894*0a6a1f1dSLionel Sambuc %x = addrspacecast i32* %gep to i32 addrspace(1)* 895*0a6a1f1dSLionel Sambuc ret i32 addrspace(1)* %x 896*0a6a1f1dSLionel Sambuc} 897*0a6a1f1dSLionel Sambuc 898*0a6a1f1dSLionel Sambuc; Do not merge the GEP and the addrspacecast, because it would undo the 899*0a6a1f1dSLionel Sambuc; addrspacecast canonicalization. 900*0a6a1f1dSLionel Sambucdefine i32 addrspace(1)* @ascast_0_0_gep([128 x i32]* %p) nounwind { 901*0a6a1f1dSLionel Sambuc; CHECK-LABEL: @ascast_0_0_gep( 902*0a6a1f1dSLionel Sambuc; CHECK-NEXT: getelementptr [128 x i32] 903*0a6a1f1dSLionel Sambuc; CHECK-NEXT: addrspacecast i32* 904*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ret i32 addrspace(1)* 905*0a6a1f1dSLionel Sambuc %gep = getelementptr [128 x i32]* %p, i32 0, i32 0 906*0a6a1f1dSLionel Sambuc %x = addrspacecast i32* %gep to i32 addrspace(1)* 907*0a6a1f1dSLionel Sambuc ret i32 addrspace(1)* %x 908*0a6a1f1dSLionel Sambuc} 909*0a6a1f1dSLionel Sambuc 910f4a2713aSLionel Sambuc; CHECK: attributes [[NUW]] = { nounwind } 911