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