xref: /aosp_15_r20/external/llvm/test/CodeGen/ARM/arm-shrink-wrapping-linux.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc %s -o - -enable-shrink-wrap=true | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
2*9880d681SAndroid Build Coastguard Worker; RUN: llc %s -o - -enable-shrink-wrap=false | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
3*9880d681SAndroid Build Coastguard Worker; We cannot merge this test with the main test for shrink-wrapping, because
4*9880d681SAndroid Build Coastguard Worker; the code path we want to exerce is not taken with ios lowering.
5*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n8:16:32-S64"
6*9880d681SAndroid Build Coastguard Workertarget triple = "armv7--linux-gnueabi"
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker@skip = internal unnamed_addr constant [2 x i8] c"\01\01", align 1
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker; Check that we do not restore the before having used the saved CSRs.
11*9880d681SAndroid Build Coastguard Worker; This happened because of a bad use of the post-dominance property.
12*9880d681SAndroid Build Coastguard Worker; The exit block of the loop happens to also lead to defs/uses of CSRs.
13*9880d681SAndroid Build Coastguard Worker; It also post-dominates the loop body and we use to generate invalid
14*9880d681SAndroid Build Coastguard Worker; restore sequence. I.e., we restored too early.
15*9880d681SAndroid Build Coastguard Worker;
16*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: wrongUseOfPostDominate:
17*9880d681SAndroid Build Coastguard Worker;
18*9880d681SAndroid Build Coastguard Worker; The prologue is the first thing happening in the function
19*9880d681SAndroid Build Coastguard Worker; without shrink-wrapping.
20*9880d681SAndroid Build Coastguard Worker; DISABLE: push
21*9880d681SAndroid Build Coastguard Worker;
22*9880d681SAndroid Build Coastguard Worker; CHECK: cmp r1, #0
23*9880d681SAndroid Build Coastguard Worker;
24*9880d681SAndroid Build Coastguard Worker; With shrink-wrapping, we branch to a pre-header, where the prologue
25*9880d681SAndroid Build Coastguard Worker; is located.
26*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: blt [[LOOP_PREHEADER:[.a-zA-Z0-9_]+]]
27*9880d681SAndroid Build Coastguard Worker; Without shrink-wrapping, we go straight into the loop.
28*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: blt [[LOOP_HEADER:[.a-zA-Z0-9_]+]]
29*9880d681SAndroid Build Coastguard Worker;
30*9880d681SAndroid Build Coastguard Worker; CHECK: @ %if.end29
31*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: pop
32*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: bx lr
33*9880d681SAndroid Build Coastguard Worker;
34*9880d681SAndroid Build Coastguard Worker; ENABLE: [[LOOP_PREHEADER]]
35*9880d681SAndroid Build Coastguard Worker; ENABLE: push
36*9880d681SAndroid Build Coastguard Worker; We must not find a pop here, otherwise that means we are in the loop
37*9880d681SAndroid Build Coastguard Worker; and are restoring before using the saved CSRs.
38*9880d681SAndroid Build Coastguard Worker; ENABLE-NOT: pop
39*9880d681SAndroid Build Coastguard Worker; ENALBE-NEXT: [[LOOP_HEADER:[.a-zA-Z0-9_]+]]: @ %while.cond2.outer
40*9880d681SAndroid Build Coastguard Worker;
41*9880d681SAndroid Build Coastguard Worker; DISABLE: [[LOOP_HEADER]]: @ %while.cond2.outer
42*9880d681SAndroid Build Coastguard Worker;
43*9880d681SAndroid Build Coastguard Worker; ENABLE-NOT: pop
44*9880d681SAndroid Build Coastguard Worker;
45*9880d681SAndroid Build Coastguard Worker; CHECK: @ %while.cond2
46*9880d681SAndroid Build Coastguard Worker; CHECK: add
47*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: cmp r{{[0-1]+}}, #1
48*9880d681SAndroid Build Coastguard Worker; Set the return value.
49*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: moveq r0,
50*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: popeq
51*9880d681SAndroid Build Coastguard Worker;
52*9880d681SAndroid Build Coastguard Worker; Use the back edge to check we get the label of the loop right.
53*9880d681SAndroid Build Coastguard Worker; This is to make sure we check the right loop pattern.
54*9880d681SAndroid Build Coastguard Worker; CHECK:  @ %while.body24.land.rhs14_crit_edge
55*9880d681SAndroid Build Coastguard Worker; CHECK: cmp r{{[0-9]+}}, #192
56*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT bhs [[LOOP_HEADER]]
57*9880d681SAndroid Build Coastguard Workerdefine fastcc i8* @wrongUseOfPostDominate(i8* readonly %s, i32 %off, i8* readnone %lim) {
58*9880d681SAndroid Build Coastguard Workerentry:
59*9880d681SAndroid Build Coastguard Worker  %cmp = icmp sgt i32 %off, -1
60*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %while.cond.preheader, label %while.cond2.outer
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Workerwhile.cond.preheader:                             ; preds = %entry
63*9880d681SAndroid Build Coastguard Worker  %tobool4 = icmp ne i32 %off, 0
64*9880d681SAndroid Build Coastguard Worker  %cmp15 = icmp ult i8* %s, %lim
65*9880d681SAndroid Build Coastguard Worker  %sel66 = and i1 %tobool4, %cmp15
66*9880d681SAndroid Build Coastguard Worker  br i1 %sel66, label %while.body, label %if.end29
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Workerwhile.body:                                       ; preds = %while.body, %while.cond.preheader
69*9880d681SAndroid Build Coastguard Worker  %s.addr.08 = phi i8* [ %add.ptr, %while.body ], [ %s, %while.cond.preheader ]
70*9880d681SAndroid Build Coastguard Worker  %off.addr.07 = phi i32 [ %dec, %while.body ], [ %off, %while.cond.preheader ]
71*9880d681SAndroid Build Coastguard Worker  %dec = add nsw i32 %off.addr.07, -1
72*9880d681SAndroid Build Coastguard Worker  %tmp = load i8, i8* %s.addr.08, align 1, !tbaa !2
73*9880d681SAndroid Build Coastguard Worker  %idxprom = zext i8 %tmp to i32
74*9880d681SAndroid Build Coastguard Worker  %arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* @skip, i32 0, i32 %idxprom
75*9880d681SAndroid Build Coastguard Worker  %tmp1 = load i8, i8* %arrayidx, align 1, !tbaa !2
76*9880d681SAndroid Build Coastguard Worker  %conv = zext i8 %tmp1 to i32
77*9880d681SAndroid Build Coastguard Worker  %add.ptr = getelementptr inbounds i8, i8* %s.addr.08, i32 %conv
78*9880d681SAndroid Build Coastguard Worker  %tobool = icmp ne i32 %off.addr.07, 1
79*9880d681SAndroid Build Coastguard Worker  %cmp1 = icmp ult i8* %add.ptr, %lim
80*9880d681SAndroid Build Coastguard Worker  %sel6 = and i1 %tobool, %cmp1
81*9880d681SAndroid Build Coastguard Worker  br i1 %sel6, label %while.body, label %if.end29
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Workerwhile.cond2.outer:                                ; preds = %while.body24.land.rhs14_crit_edge, %while.body24, %land.rhs14.preheader, %if.then7, %entry
84*9880d681SAndroid Build Coastguard Worker  %off.addr.1.ph = phi i32 [ %off, %entry ], [ %inc, %land.rhs14.preheader ], [ %inc, %if.then7 ], [ %inc, %while.body24.land.rhs14_crit_edge ], [ %inc, %while.body24 ]
85*9880d681SAndroid Build Coastguard Worker  %s.addr.1.ph = phi i8* [ %s, %entry ], [ %incdec.ptr, %land.rhs14.preheader ], [ %incdec.ptr, %if.then7 ], [ %lsr.iv, %while.body24.land.rhs14_crit_edge ], [ %lsr.iv, %while.body24 ]
86*9880d681SAndroid Build Coastguard Worker  br label %while.cond2
87*9880d681SAndroid Build Coastguard Worker
88*9880d681SAndroid Build Coastguard Workerwhile.cond2:                                      ; preds = %while.body4, %while.cond2.outer
89*9880d681SAndroid Build Coastguard Worker  %off.addr.1 = phi i32 [ %inc, %while.body4 ], [ %off.addr.1.ph, %while.cond2.outer ]
90*9880d681SAndroid Build Coastguard Worker  %inc = add nsw i32 %off.addr.1, 1
91*9880d681SAndroid Build Coastguard Worker  %tobool3 = icmp eq i32 %off.addr.1, 0
92*9880d681SAndroid Build Coastguard Worker  br i1 %tobool3, label %if.end29, label %while.body4
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Workerwhile.body4:                                      ; preds = %while.cond2
95*9880d681SAndroid Build Coastguard Worker  %tmp2 = icmp ugt i8* %s.addr.1.ph, %lim
96*9880d681SAndroid Build Coastguard Worker  br i1 %tmp2, label %if.then7, label %while.cond2
97*9880d681SAndroid Build Coastguard Worker
98*9880d681SAndroid Build Coastguard Workerif.then7:                                         ; preds = %while.body4
99*9880d681SAndroid Build Coastguard Worker  %incdec.ptr = getelementptr inbounds i8, i8* %s.addr.1.ph, i32 -1
100*9880d681SAndroid Build Coastguard Worker  %tmp3 = load i8, i8* %incdec.ptr, align 1, !tbaa !2
101*9880d681SAndroid Build Coastguard Worker  %conv1525 = zext i8 %tmp3 to i32
102*9880d681SAndroid Build Coastguard Worker  %tobool9 = icmp slt i8 %tmp3, 0
103*9880d681SAndroid Build Coastguard Worker  %cmp129 = icmp ugt i8* %incdec.ptr, %lim
104*9880d681SAndroid Build Coastguard Worker  %or.cond13 = and i1 %tobool9, %cmp129
105*9880d681SAndroid Build Coastguard Worker  br i1 %or.cond13, label %land.rhs14.preheader, label %while.cond2.outer
106*9880d681SAndroid Build Coastguard Worker
107*9880d681SAndroid Build Coastguard Workerland.rhs14.preheader:                             ; preds = %if.then7
108*9880d681SAndroid Build Coastguard Worker  %cmp1624 = icmp slt i8 %tmp3, 0
109*9880d681SAndroid Build Coastguard Worker  %cmp2026 = icmp ult i32 %conv1525, 192
110*9880d681SAndroid Build Coastguard Worker  %or.cond27 = and i1 %cmp1624, %cmp2026
111*9880d681SAndroid Build Coastguard Worker  br i1 %or.cond27, label %while.body24.preheader, label %while.cond2.outer
112*9880d681SAndroid Build Coastguard Worker
113*9880d681SAndroid Build Coastguard Workerwhile.body24.preheader:                           ; preds = %land.rhs14.preheader
114*9880d681SAndroid Build Coastguard Worker  %scevgep = getelementptr i8, i8* %s.addr.1.ph, i32 -2
115*9880d681SAndroid Build Coastguard Worker  br label %while.body24
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Workerwhile.body24:                                     ; preds = %while.body24.land.rhs14_crit_edge, %while.body24.preheader
118*9880d681SAndroid Build Coastguard Worker  %lsr.iv = phi i8* [ %scevgep, %while.body24.preheader ], [ %scevgep34, %while.body24.land.rhs14_crit_edge ]
119*9880d681SAndroid Build Coastguard Worker  %cmp12 = icmp ugt i8* %lsr.iv, %lim
120*9880d681SAndroid Build Coastguard Worker  br i1 %cmp12, label %while.body24.land.rhs14_crit_edge, label %while.cond2.outer
121*9880d681SAndroid Build Coastguard Worker
122*9880d681SAndroid Build Coastguard Workerwhile.body24.land.rhs14_crit_edge:                ; preds = %while.body24
123*9880d681SAndroid Build Coastguard Worker  %.pre = load i8, i8* %lsr.iv, align 1, !tbaa !2
124*9880d681SAndroid Build Coastguard Worker  %cmp16 = icmp slt i8 %.pre, 0
125*9880d681SAndroid Build Coastguard Worker  %conv15 = zext i8 %.pre to i32
126*9880d681SAndroid Build Coastguard Worker  %cmp20 = icmp ult i32 %conv15, 192
127*9880d681SAndroid Build Coastguard Worker  %or.cond = and i1 %cmp16, %cmp20
128*9880d681SAndroid Build Coastguard Worker  %scevgep34 = getelementptr i8, i8* %lsr.iv, i32 -1
129*9880d681SAndroid Build Coastguard Worker  br i1 %or.cond, label %while.body24, label %while.cond2.outer
130*9880d681SAndroid Build Coastguard Worker
131*9880d681SAndroid Build Coastguard Workerif.end29:                                         ; preds = %while.cond2, %while.body, %while.cond.preheader
132*9880d681SAndroid Build Coastguard Worker  %s.addr.3 = phi i8* [ %s, %while.cond.preheader ], [ %add.ptr, %while.body ], [ %s.addr.1.ph, %while.cond2 ]
133*9880d681SAndroid Build Coastguard Worker  ret i8* %s.addr.3
134*9880d681SAndroid Build Coastguard Worker}
135*9880d681SAndroid Build Coastguard Worker
136*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!0, !1}
137*9880d681SAndroid Build Coastguard Worker
138*9880d681SAndroid Build Coastguard Worker!0 = !{i32 1, !"wchar_size", i32 4}
139*9880d681SAndroid Build Coastguard Worker!1 = !{i32 1, !"min_enum_size", i32 4}
140*9880d681SAndroid Build Coastguard Worker!2 = !{!3, !3, i64 0}
141*9880d681SAndroid Build Coastguard Worker!3 = !{!"omnipotent char", !4, i64 0}
142*9880d681SAndroid Build Coastguard Worker!4 = !{!"Simple C/C++ TBAA"}
143