76 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S -passes="separate-const-offset-from-gep<lower-gep>" < %s | FileCheck %s3 4; Check that GEP with an index 'A - B + [ConstantInt]' will be split into two5; GEPs. eg.6; %A = ...7; %B = ...8; %sub = %A - %B9; %idx = %sub + 1010; %gep = getelementptr int, ptr %p, %idx11; will be transformed into:12; %A = ...13; %B = ...14; %sub = %A - %B15; %gep_base = getelementptr int, ptr %p, %sub16; %gep = getelementptr int, ptr %gep_base, 1017 18define void @test_A_sub_B_add_ConstantInt(ptr %p) {19; CHECK-LABEL: @test_A_sub_B_add_ConstantInt(20; CHECK-NEXT: entry:21; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo()22; CHECK-NEXT: [[REM:%.*]] = srem i32 [[TMP0]], 523; CHECK-NEXT: br label [[FOR_BODY:%.*]]24; CHECK: for.body:25; CHECK-NEXT: [[K:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[COND_END:%.*]] ]26; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[K]], 527; CHECK-NEXT: [[SUB1:%.*]] = sub nsw i32 [[MUL]], [[REM]]28; CHECK-NEXT: [[CMP26:%.*]] = icmp ult i32 [[SUB1]], 51229; CHECK-NEXT: br i1 [[CMP26]], label [[COND_TRUE:%.*]], label [[COND_END]]30; CHECK: cond.true:31; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[MUL]] to i6432; CHECK-NEXT: [[TMP2:%.*]] = sext i32 [[REM]] to i6433; CHECK-NEXT: [[SUB22:%.*]] = sub i64 [[TMP2]], [[TMP1]]34; CHECK-NEXT: [[TMP4:%.*]] = shl i64 [[SUB22]], 235; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 204436; CHECK-NEXT: [[TMP7:%.*]] = getelementptr i8, ptr [[UGLYGEP]], i64 [[TMP4]]37; CHECK-NEXT: store float 1.000000e+00, ptr [[TMP7]], align 438; CHECK-NEXT: br label [[COND_END]]39; CHECK: cond.end:40; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[K]], 141; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INC]], 10042; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END:%.*]]43; CHECK: for.end:44; CHECK-NEXT: ret void45;46entry:47 %0 = tail call i32 @foo()48 %rem = srem i32 %0, 549 %add = add nsw i32 %rem , 51150 br label %for.body51 52for.body:53 %k = phi i32 [ 0, %entry ], [ %inc, %cond.end ]54 %mul = mul nuw nsw i32 %k, 555 %sub1 = sub nsw i32 %mul, %rem56 %cmp26 = icmp ult i32 %sub1, 51257 br i1 %cmp26, label %cond.true, label %cond.end58 59cond.true:60 %sub2 = sub nsw i32 %add, %mul61 %idxprom = sext i32 %sub2 to i6462 %arryidx = getelementptr inbounds float, ptr %p, i64 %idxprom63 store float 1.0, ptr %arryidx, align 464 br label %cond.end65 66cond.end:67 %inc = add nuw nsw i32 %k, 168 %exitcond = icmp ne i32 %inc, 10069 br i1 %exitcond, label %for.body, label %for.end70 71for.end:72 ret void73}74 75declare i32 @foo()76