xref: /llvm-project/llvm/test/Transforms/LoopStrengthReduce/duplicated-phis.ll (revision 1f2a634c44dedef11f590956f297b2c7a1659fcf)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2; RUN: opt -S -loop-reduce %s | FileCheck %s
3; REQUIRES: x86-registered-target
4
5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-unknown-linux-gnu"
7
8define i64 @test_duplicated_phis(i64 noundef %N) {
9; CHECK-LABEL: define i64 @test_duplicated_phis(
10; CHECK-SAME: i64 noundef [[N:%.*]]) {
11; CHECK-NEXT:  [[ENTRY:.*]]:
12; CHECK-NEXT:    [[MUL:%.*]] = shl i64 [[N]], 1
13; CHECK-NEXT:    [[CMP6_NOT:%.*]] = icmp eq i64 [[MUL]], 0
14; CHECK-NEXT:    br i1 [[CMP6_NOT]], label %[[FOR_END:.*]], label %[[FOR_BODY_PREHEADER:.*]]
15; CHECK:       [[FOR_BODY_PREHEADER]]:
16; CHECK-NEXT:    [[TMP0:%.*]] = icmp ult i64 [[MUL]], 4
17; CHECK-NEXT:    br i1 [[TMP0]], label %[[FOR_END_LOOPEXIT_UNR_LCSSA:.*]], label %[[FOR_BODY_PREHEADER_NEW:.*]]
18; CHECK:       [[FOR_BODY_PREHEADER_NEW]]:
19; CHECK-NEXT:    [[UNROLL_ITER:%.*]] = and i64 [[MUL]], -4
20; CHECK-NEXT:    [[TMP4:%.*]] = add i64 [[UNROLL_ITER]], -4
21; CHECK-NEXT:    [[TMP5:%.*]] = lshr i64 [[TMP4]], 2
22; CHECK-NEXT:    [[TMP3:%.*]] = shl nuw nsw i64 [[TMP5]], 1
23; CHECK-NEXT:    [[LSR_IV_NEXT:%.*]] = sub i64 -3, [[TMP3]]
24; CHECK-NEXT:    br label %[[FOR_BODY:.*]]
25; CHECK:       [[FOR_BODY]]:
26; CHECK-NEXT:    [[I_07:%.*]] = phi i64 [ 0, %[[FOR_BODY_PREHEADER_NEW]] ], [ [[INC_3:%.*]], %[[FOR_BODY]] ]
27; CHECK-NEXT:    [[INC_3]] = add i64 [[I_07]], 4
28; CHECK-NEXT:    [[NITER_NCMP_3_NOT:%.*]] = icmp eq i64 [[UNROLL_ITER]], [[INC_3]]
29; CHECK-NEXT:    br i1 [[NITER_NCMP_3_NOT]], label %[[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT:.*]], label %[[FOR_BODY]]
30; CHECK:       [[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT]]:
31; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[LSR_IV_NEXT]], 1
32; CHECK-NEXT:    br label %[[FOR_END_LOOPEXIT_UNR_LCSSA]]
33; CHECK:       [[FOR_END_LOOPEXIT_UNR_LCSSA]]:
34; CHECK-NEXT:    [[RES_1_LCSSA_PH:%.*]] = phi i64 [ undef, %[[FOR_BODY_PREHEADER]] ], [ [[TMP1]], %[[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ]
35; CHECK-NEXT:    [[RES_09_UNR:%.*]] = phi i64 [ -1, %[[FOR_BODY_PREHEADER]] ], [ [[LSR_IV_NEXT]], %[[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ]
36; CHECK-NEXT:    [[TMP2:%.*]] = and i64 [[N]], 1
37; CHECK-NEXT:    [[LCMP_MOD_NOT:%.*]] = icmp eq i64 [[TMP2]], 0
38; CHECK-NEXT:    [[SPEC_SELECT:%.*]] = select i1 [[LCMP_MOD_NOT]], i64 [[RES_1_LCSSA_PH]], i64 [[RES_09_UNR]]
39; CHECK-NEXT:    br label %[[FOR_END]]
40; CHECK:       [[FOR_END]]:
41; CHECK-NEXT:    [[RES_0_LCSSA:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[SPEC_SELECT]], %[[FOR_END_LOOPEXIT_UNR_LCSSA]] ]
42; CHECK-NEXT:    ret i64 [[RES_0_LCSSA]]
43;
44entry:
45  %mul = shl i64 %N, 1
46  %cmp6.not = icmp eq i64 %mul, 0
47  br i1 %cmp6.not, label %for.end, label %for.body.preheader
48
49for.body.preheader:
50  %0 = icmp ult i64 %mul, 4
51  br i1 %0, label %for.end.loopexit.unr-lcssa, label %for.body.preheader.new
52
53for.body.preheader.new:
54  %unroll_iter = and i64 %mul, -4
55  br label %for.body
56
57for.body:
58  %res.09 = phi i64 [ 0, %for.body.preheader.new ], [ %res.1.3, %for.body ]
59  %i.07 = phi i64 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
60  %niter = phi i64 [ 0, %for.body.preheader.new ], [ %niter.next.3, %for.body ]
61  %res.1.1 = add i64 %res.09, -1
62  %inc.1 = or disjoint i64 %i.07, 2
63  %res.1.2 = add i64 %inc.1, %res.1.1
64  %reass.sub = sub i64 %res.1.2, %i.07
65  %res.1.3 = add i64 %reass.sub, -3
66  %inc.3 = add nuw i64 %i.07, 4
67  %niter.next.3 = add i64 %niter, 4
68  %niter.ncmp.3.not = icmp eq i64 %niter.next.3, %unroll_iter
69  br i1 %niter.ncmp.3.not, label %for.end.loopexit.unr-lcssa.loopexit, label %for.body
70
71for.end.loopexit.unr-lcssa.loopexit:
72  %1 = add i64 %reass.sub, -4
73  br label %for.end.loopexit.unr-lcssa
74
75for.end.loopexit.unr-lcssa:
76  %res.1.lcssa.ph = phi i64 [ undef, %for.body.preheader ], [ %res.1.3, %for.end.loopexit.unr-lcssa.loopexit ]
77  %res.09.unr = phi i64 [ -1, %for.body.preheader ], [ %1, %for.end.loopexit.unr-lcssa.loopexit ]
78  %2 = and i64 %N, 1
79  %lcmp.mod.not = icmp eq i64 %2, 0
80  %spec.select = select i1 %lcmp.mod.not, i64 %res.1.lcssa.ph, i64 %res.09.unr
81  br label %for.end
82
83for.end:
84  %res.0.lcssa = phi i64 [ 0, %entry ], [ %spec.select, %for.end.loopexit.unr-lcssa ]
85  ret i64 %res.0.lcssa
86}
87