xref: /llvm-project/llvm/test/CodeGen/AArch64/selectopt-logical.ll (revision ce08c7ee1e86ec6d4c02e19db6724d16a578a48b)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -select-optimize -mtriple=aarch64-linux-gnu -mcpu=neoverse-v2 -S < %s | FileCheck %s
3; RUN: opt -passes='require<profile-summary>,function(select-optimize)' -mtriple=aarch64-linux-gnu -mcpu=neoverse-v2 -S < %s | FileCheck %s
4
5define i32 @test(ptr nocapture noundef readnone %x, i32 noundef %iters) {
6; CHECK-LABEL: @test(
7; CHECK-NEXT:  entry:
8; CHECK-NEXT:    [[CMP3:%.*]] = icmp sgt i32 [[ITERS:%.*]], 0
9; CHECK-NEXT:    br i1 [[CMP3]], label [[FOR_BODY_I_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
10; CHECK:       for.body.i.preheader:
11; CHECK-NEXT:    [[I_05:%.*]] = phi i32 [ [[INC:%.*]], [[INNER_LOOP_010_EXIT:%.*]] ], [ 0, [[ENTRY:%.*]] ]
12; CHECK-NEXT:    [[RES_04:%.*]] = phi i32 [ [[OR:%.*]], [[INNER_LOOP_010_EXIT]] ], [ 0, [[ENTRY]] ]
13; CHECK-NEXT:    br label [[FOR_BODY_I:%.*]]
14; CHECK:       for.cond.cleanup:
15; CHECK-NEXT:    [[RES_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[OR]], [[INNER_LOOP_010_EXIT]] ]
16; CHECK-NEXT:    ret i32 [[RES_0_LCSSA]]
17; CHECK:       for.body.i:
18; CHECK-NEXT:    [[INDVARS_IV_I:%.*]] = phi i64 [ 0, [[FOR_BODY_I_PREHEADER]] ], [ [[INDVARS_IV_NEXT_I_4:%.*]], [[FOR_BODY_I]] ]
19; CHECK-NEXT:    [[ALL_0_OFF010_I:%.*]] = phi i1 [ true, [[FOR_BODY_I_PREHEADER]] ], [ [[ALL_0_OFF0__I_4:%.*]], [[FOR_BODY_I]] ]
20; CHECK-NEXT:    [[ANY_0_OFF09_I:%.*]] = phi i1 [ false, [[FOR_BODY_I_PREHEADER]] ], [ [[DOTANY_0_OFF0_I_4:%.*]], [[FOR_BODY_I]] ]
21; CHECK-NEXT:    [[ARRAYIDX_I:%.*]] = getelementptr inbounds float, ptr [[X:%.*]], i64 [[INDVARS_IV_I]]
22; CHECK-NEXT:    [[TMP0:%.*]] = load float, ptr [[ARRAYIDX_I]], align 4
23; CHECK-NEXT:    [[CMP1_I:%.*]] = fcmp fast olt float [[TMP0]], 0.000000e+00
24; CHECK-NEXT:    [[INDVARS_IV_NEXT_I:%.*]] = add nuw nsw i64 [[INDVARS_IV_I]], 1
25; CHECK-NEXT:    [[ARRAYIDX_I_1:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[INDVARS_IV_NEXT_I]]
26; CHECK-NEXT:    [[TMP1:%.*]] = load float, ptr [[ARRAYIDX_I_1]], align 4
27; CHECK-NEXT:    [[CMP1_I_1:%.*]] = fcmp fast olt float [[TMP1]], 0.000000e+00
28; CHECK-NEXT:    [[INDVARS_IV_NEXT_I_1:%.*]] = add nuw nsw i64 [[INDVARS_IV_I]], 2
29; CHECK-NEXT:    [[ARRAYIDX_I_2:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[INDVARS_IV_NEXT_I_1]]
30; CHECK-NEXT:    [[TMP2:%.*]] = load float, ptr [[ARRAYIDX_I_2]], align 4
31; CHECK-NEXT:    [[CMP1_I_2:%.*]] = fcmp fast olt float [[TMP2]], 0.000000e+00
32; CHECK-NEXT:    [[INDVARS_IV_NEXT_I_2:%.*]] = add nuw nsw i64 [[INDVARS_IV_I]], 3
33; CHECK-NEXT:    [[ARRAYIDX_I_3:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[INDVARS_IV_NEXT_I_2]]
34; CHECK-NEXT:    [[TMP3:%.*]] = load float, ptr [[ARRAYIDX_I_3]], align 4
35; CHECK-NEXT:    [[CMP1_I_3:%.*]] = fcmp fast olt float [[TMP3]], 0.000000e+00
36; CHECK-NEXT:    [[INDVARS_IV_NEXT_I_3:%.*]] = add nuw nsw i64 [[INDVARS_IV_I]], 4
37; CHECK-NEXT:    [[ARRAYIDX_I_4:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[INDVARS_IV_NEXT_I_3]]
38; CHECK-NEXT:    [[TMP4:%.*]] = load float, ptr [[ARRAYIDX_I_4]], align 4
39; CHECK-NEXT:    [[CMP1_I_4:%.*]] = fcmp fast olt float [[TMP4]], 0.000000e+00
40; CHECK-NEXT:    [[TMP5:%.*]] = select i1 [[CMP1_I_4]], i1 true, i1 [[CMP1_I_3]]
41; CHECK-NEXT:    [[TMP6:%.*]] = select i1 [[TMP5]], i1 true, i1 [[CMP1_I_2]]
42; CHECK-NEXT:    [[TMP7:%.*]] = select i1 [[TMP6]], i1 true, i1 [[CMP1_I_1]]
43; CHECK-NEXT:    [[TMP8:%.*]] = select i1 [[TMP7]], i1 true, i1 [[CMP1_I]]
44; CHECK-NEXT:    [[DOTANY_0_OFF0_I_4]] = select i1 [[TMP8]], i1 true, i1 [[ANY_0_OFF09_I]]
45; CHECK-NEXT:    [[TMP9:%.*]] = select i1 [[CMP1_I_4]], i1 [[CMP1_I_3]], i1 false
46; CHECK-NEXT:    [[TMP10:%.*]] = select i1 [[TMP9]], i1 [[CMP1_I_2]], i1 false
47; CHECK-NEXT:    [[TMP11:%.*]] = select i1 [[TMP10]], i1 [[CMP1_I_1]], i1 false
48; CHECK-NEXT:    [[TMP12:%.*]] = select i1 [[TMP11]], i1 [[CMP1_I]], i1 false
49; CHECK-NEXT:    [[ALL_0_OFF0__I_4]] = select i1 [[TMP12]], i1 [[ALL_0_OFF010_I]], i1 false
50; CHECK-NEXT:    [[INDVARS_IV_NEXT_I_4]] = add nuw nsw i64 [[INDVARS_IV_I]], 5
51; CHECK-NEXT:    [[EXITCOND_NOT_I_4:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT_I_4]], 10000
52; CHECK-NEXT:    br i1 [[EXITCOND_NOT_I_4]], label [[INNER_LOOP_010_EXIT]], label [[FOR_BODY_I]]
53; CHECK:       inner_loop_010.exit:
54; CHECK-NEXT:    [[TMP13:%.*]] = select i1 [[DOTANY_0_OFF0_I_4]], i32 2, i32 3
55; CHECK-NEXT:    [[TMP14:%.*]] = select i1 [[ALL_0_OFF0__I_4]], i32 1, i32 [[TMP13]]
56; CHECK-NEXT:    [[OR]] = or i32 [[TMP14]], [[RES_04]]
57; CHECK-NEXT:    [[INC]] = add nuw nsw i32 [[I_05]], 1
58; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[ITERS]]
59; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY_I_PREHEADER]]
60;
61entry:
62  %cmp3 = icmp sgt i32 %iters, 0
63  br i1 %cmp3, label %for.body.i.preheader, label %for.cond.cleanup
64
65for.body.i.preheader:                             ; preds = %entry, %inner_loop_010.exit
66  %i.05 = phi i32 [ %inc, %inner_loop_010.exit ], [ 0, %entry ]
67  %res.04 = phi i32 [ %or, %inner_loop_010.exit ], [ 0, %entry ]
68  br label %for.body.i
69
70for.cond.cleanup:                                 ; preds = %inner_loop_010.exit, %entry
71  %res.0.lcssa = phi i32 [ 0, %entry ], [ %or, %inner_loop_010.exit ]
72  ret i32 %res.0.lcssa
73
74for.body.i:                                       ; preds = %for.body.i, %for.body.i.preheader
75  %indvars.iv.i = phi i64 [ 0, %for.body.i.preheader ], [ %indvars.iv.next.i.4, %for.body.i ]
76  %all.0.off010.i = phi i1 [ true, %for.body.i.preheader ], [ %all.0.off0..i.4, %for.body.i ]
77  %any.0.off09.i = phi i1 [ false, %for.body.i.preheader ], [ %.any.0.off0.i.4, %for.body.i ]
78  %arrayidx.i = getelementptr inbounds float, ptr %x, i64 %indvars.iv.i
79  %0 = load float, ptr %arrayidx.i, align 4
80  %cmp1.i = fcmp fast olt float %0, 0.000000e+00
81  %indvars.iv.next.i = add nuw nsw i64 %indvars.iv.i, 1
82  %arrayidx.i.1 = getelementptr inbounds float, ptr %x, i64 %indvars.iv.next.i
83  %1 = load float, ptr %arrayidx.i.1, align 4
84  %cmp1.i.1 = fcmp fast olt float %1, 0.000000e+00
85  %indvars.iv.next.i.1 = add nuw nsw i64 %indvars.iv.i, 2
86  %arrayidx.i.2 = getelementptr inbounds float, ptr %x, i64 %indvars.iv.next.i.1
87  %2 = load float, ptr %arrayidx.i.2, align 4
88  %cmp1.i.2 = fcmp fast olt float %2, 0.000000e+00
89  %indvars.iv.next.i.2 = add nuw nsw i64 %indvars.iv.i, 3
90  %arrayidx.i.3 = getelementptr inbounds float, ptr %x, i64 %indvars.iv.next.i.2
91  %3 = load float, ptr %arrayidx.i.3, align 4
92  %cmp1.i.3 = fcmp fast olt float %3, 0.000000e+00
93  %indvars.iv.next.i.3 = add nuw nsw i64 %indvars.iv.i, 4
94  %arrayidx.i.4 = getelementptr inbounds float, ptr %x, i64 %indvars.iv.next.i.3
95  %4 = load float, ptr %arrayidx.i.4, align 4
96  %cmp1.i.4 = fcmp fast olt float %4, 0.000000e+00
97  %5 = select i1 %cmp1.i.4, i1 true, i1 %cmp1.i.3
98  %6 = select i1 %5, i1 true, i1 %cmp1.i.2
99  %7 = select i1 %6, i1 true, i1 %cmp1.i.1
100  %8 = select i1 %7, i1 true, i1 %cmp1.i
101  %.any.0.off0.i.4 = select i1 %8, i1 true, i1 %any.0.off09.i
102  %9 = select i1 %cmp1.i.4, i1 %cmp1.i.3, i1 false
103  %10 = select i1 %9, i1 %cmp1.i.2, i1 false
104  %11 = select i1 %10, i1 %cmp1.i.1, i1 false
105  %12 = select i1 %11, i1 %cmp1.i, i1 false
106  %all.0.off0..i.4 = select i1 %12, i1 %all.0.off010.i, i1 false
107  %indvars.iv.next.i.4 = add nuw nsw i64 %indvars.iv.i, 5
108  %exitcond.not.i.4 = icmp eq i64 %indvars.iv.next.i.4, 10000
109  br i1 %exitcond.not.i.4, label %inner_loop_010.exit, label %for.body.i
110
111inner_loop_010.exit:                              ; preds = %for.body.i
112  %13 = select i1 %.any.0.off0.i.4, i32 2, i32 3
113  %14 = select i1 %all.0.off0..i.4, i32 1, i32 %13
114  %or = or i32 %14, %res.04
115  %inc = add nuw nsw i32 %i.05, 1
116  %exitcond.not = icmp eq i32 %inc, %iters
117  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body.i.preheader
118}
119