1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt < %s -loop-reduce -gvn -S | FileCheck %s
4 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
6 ; LoopStrengthReduce should reuse %mul as the stride.
7 define void @_Z3fooPfll(ptr nocapture readonly %input, i64 %n, i64 %s) {
8 ; CHECK-LABEL: define void @_Z3fooPfll
9 ; CHECK-SAME: (ptr nocapture readonly [[INPUT:%.*]], i64 [[N:%.*]], i64 [[S:%.*]]) {
11 ; CHECK-NEXT: [[MUL:%.*]] = shl i64 [[S]], 2
12 ; CHECK-NEXT: tail call void @_Z3bazl(i64 [[MUL]])
13 ; CHECK-NEXT: [[CMP_5:%.*]] = icmp sgt i64 [[N]], 0
14 ; CHECK-NEXT: br i1 [[CMP_5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
15 ; CHECK: for.body.preheader:
16 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
17 ; CHECK: for.cond.cleanup.loopexit:
18 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
19 ; CHECK: for.cond.cleanup:
20 ; CHECK-NEXT: ret void
22 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi ptr [ [[SCEVGEP:%.*]], [[FOR_BODY]] ], [ [[INPUT]], [[FOR_BODY_PREHEADER]] ]
23 ; CHECK-NEXT: [[I_06:%.*]] = phi i64 [ [[ADD:%.*]], [[FOR_BODY]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
24 ; CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[LSR_IV]], align 4
25 ; CHECK-NEXT: tail call void @_Z3barf(float [[TMP0]])
26 ; CHECK-NEXT: [[ADD]] = add i64 [[I_06]], [[S]]
27 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV]], i64 [[MUL]]
28 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[ADD]], [[N]]
29 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
32 %mul = shl nsw i64 %s, 2
33 tail call void @_Z3bazl(i64 %mul) #2
34 %cmp.5 = icmp sgt i64 %n, 0
35 br i1 %cmp.5, label %for.body.preheader, label %for.cond.cleanup
37 for.body.preheader: ; preds = %entry
40 for.cond.cleanup.loopexit: ; preds = %for.body
41 br label %for.cond.cleanup
43 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
46 for.body: ; preds = %for.body.preheader, %for.body
47 %i.06 = phi i64 [ %add, %for.body ], [ 0, %for.body.preheader ]
48 %arrayidx = getelementptr inbounds float, ptr %input, i64 %i.06
49 %0 = load float, ptr %arrayidx, align 4
50 tail call void @_Z3barf(float %0) #2
51 %add = add nsw i64 %i.06, %s
52 %cmp = icmp slt i64 %add, %n
53 br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit
56 declare void @_Z3bazl(i64)
58 declare void @_Z3barf(float)