1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes="separate-const-offset-from-gep<lower-gep>" < %s | FileCheck %s
4 ; Check that GEP with an index 'A - B + [ConstantInt]' will be split into two
10 ; %gep = getelementptr int, ptr %p, %idx
11 ; will be transformed into:
15 ; %gep_base = getelementptr int, ptr %p, %sub
16 ; %gep = getelementptr int, ptr %gep_base, 10
18 define void @test_A_sub_B_add_ConstantInt(ptr %p) {
19 ; CHECK-LABEL: @test_A_sub_B_add_ConstantInt(
21 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo()
22 ; CHECK-NEXT: [[REM:%.*]] = srem i32 [[TMP0]], 5
23 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
25 ; CHECK-NEXT: [[K:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[COND_END:%.*]] ]
26 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[K]], 5
27 ; CHECK-NEXT: [[SUB1:%.*]] = sub nsw i32 [[MUL]], [[REM]]
28 ; CHECK-NEXT: [[CMP26:%.*]] = icmp ult i32 [[SUB1]], 512
29 ; CHECK-NEXT: br i1 [[CMP26]], label [[COND_TRUE:%.*]], label [[COND_END]]
31 ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[MUL]] to i64
32 ; CHECK-NEXT: [[TMP2:%.*]] = sext i32 [[REM]] to i64
33 ; CHECK-NEXT: [[SUB22:%.*]] = sub i64 [[TMP2]], [[TMP1]]
34 ; CHECK-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[P:%.*]] to i64
35 ; CHECK-NEXT: [[TMP4:%.*]] = shl i64 [[SUB22]], 2
36 ; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[TMP3]], [[TMP4]]
37 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP5]], 2044
38 ; CHECK-NEXT: [[TMP7:%.*]] = inttoptr i64 [[TMP6]] to ptr
39 ; CHECK-NEXT: store float 1.000000e+00, ptr [[TMP7]], align 4
40 ; CHECK-NEXT: br label [[COND_END]]
42 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[K]], 1
43 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INC]], 100
44 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END:%.*]]
46 ; CHECK-NEXT: ret void
49 %0 = tail call i32 @foo()
51 %add = add nsw i32 %rem , 511
55 %k = phi i32 [ 0, %entry ], [ %inc, %cond.end ]
56 %mul = mul nuw nsw i32 %k, 5
57 %sub1 = sub nsw i32 %mul, %rem
58 %cmp26 = icmp ult i32 %sub1, 512
59 br i1 %cmp26, label %cond.true, label %cond.end
62 %sub2 = sub nsw i32 %add, %mul
63 %idxprom = sext i32 %sub2 to i64
64 %arryidx = getelementptr inbounds float, ptr %p, i64 %idxprom
65 store float 1.0, ptr %arryidx, align 4
69 %inc = add nuw nsw i32 %k, 1
70 %exitcond = icmp ne i32 %inc, 100
71 br i1 %exitcond, label %for.body, label %for.end