xref: /llvm-project/llvm/test/Transforms/JumpThreading/codesize-loop.ll (revision fc6bdb8549842613da51b9d570b29e27cc709f69)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -passes=jump-threading -S %s -o - | FileCheck %s --check-prefix=DEFAULT
3; RUN: opt -passes=jump-threading -S -jump-threading-threshold=6 %s -o - | FileCheck %s --check-prefix=OVERIDE
4
5@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
6define i32 @test_minsize(i32 %argc, ptr nocapture readonly %argv) local_unnamed_addr #0 {
7; DEFAULT-LABEL: @test_minsize(
8; DEFAULT-NEXT:  entry:
9; DEFAULT-NEXT:    [[CMP:%.*]] = icmp eq i32 [[ARGC:%.*]], 2
10; DEFAULT-NEXT:    br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
11; DEFAULT:       cond.true:
12; DEFAULT-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds ptr, ptr [[ARGV:%.*]], i32 1
13; DEFAULT-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[ARRAYIDX]], align 4
14; DEFAULT-NEXT:    [[CALL:%.*]] = tail call i32 @atoi(ptr [[TMP0]])
15; DEFAULT-NEXT:    br label [[COND_END]]
16; DEFAULT:       cond.end:
17; DEFAULT-NEXT:    [[COND:%.*]] = phi i32 [ [[CALL]], [[COND_TRUE]] ], [ 46, [[ENTRY:%.*]] ]
18; DEFAULT-NEXT:    [[TMP1:%.*]] = mul i32 [[COND]], [[COND]]
19; DEFAULT-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
20; DEFAULT-NEXT:    [[TMP3:%.*]] = mul i32 [[COND]], [[TMP2]]
21; DEFAULT-NEXT:    [[TMP4:%.*]] = icmp sgt i32 [[COND]], 0
22; DEFAULT-NEXT:    [[COND_FR:%.*]] = freeze i1 [[TMP4]]
23; DEFAULT-NEXT:    br i1 [[COND_FR]], label [[TMP5:%.*]], label [[TMP6:%.*]]
24; DEFAULT:       5:
25; DEFAULT-NEXT:    br label [[TMP6]]
26; DEFAULT:       6:
27; DEFAULT-NEXT:    [[TMP7:%.*]] = phi i32 [ [[COND]], [[TMP5]] ], [ 0, [[COND_END]] ]
28; DEFAULT-NEXT:    [[TMP8:%.*]] = mul i32 [[TMP3]], [[TMP7]]
29; DEFAULT-NEXT:    [[CALL33:%.*]] = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i32 [[TMP8]])
30; DEFAULT-NEXT:    ret i32 0
31;
32; OVERIDE-LABEL: @test_minsize(
33; OVERIDE-NEXT:  entry:
34; OVERIDE-NEXT:    [[CMP:%.*]] = icmp eq i32 [[ARGC:%.*]], 2
35; OVERIDE-NEXT:    br i1 [[CMP]], label [[COND_END:%.*]], label [[COND_END_THREAD:%.*]]
36; OVERIDE:       cond.end:
37; OVERIDE-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds ptr, ptr [[ARGV:%.*]], i32 1
38; OVERIDE-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[ARRAYIDX]], align 4
39; OVERIDE-NEXT:    [[CALL:%.*]] = tail call i32 @atoi(ptr [[TMP0]])
40; OVERIDE-NEXT:    [[TMP1:%.*]] = mul i32 [[CALL]], [[CALL]]
41; OVERIDE-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
42; OVERIDE-NEXT:    [[TMP3:%.*]] = mul i32 [[CALL]], [[TMP2]]
43; OVERIDE-NEXT:    [[TMP4:%.*]] = icmp sgt i32 [[CALL]], 0
44; OVERIDE-NEXT:    [[COND_FR:%.*]] = freeze i1 [[TMP4]]
45; OVERIDE-NEXT:    br i1 [[COND_FR]], label [[TMP5:%.*]], label [[COND_END_THREAD]]
46; OVERIDE:       5:
47; OVERIDE-NEXT:    br label [[COND_END_THREAD]]
48; OVERIDE:       cond.end.thread:
49; OVERIDE-NEXT:    [[TMP6:%.*]] = phi i32 [ [[TMP3]], [[COND_END]] ], [ [[TMP3]], [[TMP5]] ], [ 205962976, [[ENTRY:%.*]] ]
50; OVERIDE-NEXT:    [[TMP7:%.*]] = phi i32 [ 0, [[COND_END]] ], [ [[CALL]], [[TMP5]] ], [ 46, [[ENTRY]] ]
51; OVERIDE-NEXT:    [[TMP8:%.*]] = mul i32 [[TMP6]], [[TMP7]]
52; OVERIDE-NEXT:    [[CALL33:%.*]] = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i32 [[TMP8]])
53; OVERIDE-NEXT:    ret i32 0
54;
55entry:
56  %cmp = icmp eq i32 %argc, 2
57  br i1 %cmp, label %cond.true, label %cond.end
58
59cond.true:                                        ; preds = %entry
60  %arrayidx = getelementptr inbounds ptr, ptr %argv, i32 1
61  %0 = load ptr, ptr %arrayidx, align 4
62  %call = tail call i32 @atoi(ptr %0)
63  br label %cond.end
64
65cond.end:                                         ; preds = %entry, %cond.true
66  %cond = phi i32 [ %call, %cond.true ], [ 46, %entry ]
67  %1 = mul i32 %cond, %cond
68  %2 = mul i32 %1, %1
69  %3 = mul i32 %cond, %2
70  %4 = icmp sgt i32 %cond, 0
71  %spec.select = select i1 %4, i32 %cond, i32 0
72  %5 = mul i32 %3, %spec.select
73  %call33 = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i32 %5) #4
74  ret i32 0
75}
76
77define i32 @test_optsize(i32 %argc, ptr nocapture readonly %argv) local_unnamed_addr #1 {
78; DEFAULT-LABEL: @test_optsize(
79; DEFAULT-NEXT:  entry:
80; DEFAULT-NEXT:    [[CMP:%.*]] = icmp eq i32 [[ARGC:%.*]], 2
81; DEFAULT-NEXT:    br i1 [[CMP]], label [[COND_END:%.*]], label [[COND_END_THREAD:%.*]]
82; DEFAULT:       cond.end:
83; DEFAULT-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds ptr, ptr [[ARGV:%.*]], i32 1
84; DEFAULT-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[ARRAYIDX]], align 4
85; DEFAULT-NEXT:    [[CALL:%.*]] = tail call i32 @atoi(ptr [[TMP0]])
86; DEFAULT-NEXT:    [[TMP1:%.*]] = mul i32 [[CALL]], [[CALL]]
87; DEFAULT-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
88; DEFAULT-NEXT:    [[TMP3:%.*]] = mul i32 [[CALL]], [[TMP2]]
89; DEFAULT-NEXT:    [[TMP4:%.*]] = icmp sgt i32 [[CALL]], 0
90; DEFAULT-NEXT:    [[COND_FR:%.*]] = freeze i1 [[TMP4]]
91; DEFAULT-NEXT:    br i1 [[COND_FR]], label [[TMP5:%.*]], label [[COND_END_THREAD]]
92; DEFAULT:       5:
93; DEFAULT-NEXT:    br label [[COND_END_THREAD]]
94; DEFAULT:       cond.end.thread:
95; DEFAULT-NEXT:    [[TMP6:%.*]] = phi i32 [ [[TMP3]], [[COND_END]] ], [ [[TMP3]], [[TMP5]] ], [ 205962976, [[ENTRY:%.*]] ]
96; DEFAULT-NEXT:    [[TMP7:%.*]] = phi i32 [ 0, [[COND_END]] ], [ [[CALL]], [[TMP5]] ], [ 46, [[ENTRY]] ]
97; DEFAULT-NEXT:    [[TMP8:%.*]] = mul i32 [[TMP6]], [[TMP7]]
98; DEFAULT-NEXT:    [[CALL33:%.*]] = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i32 [[TMP8]])
99; DEFAULT-NEXT:    ret i32 0
100;
101; OVERIDE-LABEL: @test_optsize(
102; OVERIDE-NEXT:  entry:
103; OVERIDE-NEXT:    [[CMP:%.*]] = icmp eq i32 [[ARGC:%.*]], 2
104; OVERIDE-NEXT:    br i1 [[CMP]], label [[COND_END:%.*]], label [[COND_END_THREAD:%.*]]
105; OVERIDE:       cond.end:
106; OVERIDE-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds ptr, ptr [[ARGV:%.*]], i32 1
107; OVERIDE-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[ARRAYIDX]], align 4
108; OVERIDE-NEXT:    [[CALL:%.*]] = tail call i32 @atoi(ptr [[TMP0]])
109; OVERIDE-NEXT:    [[TMP1:%.*]] = mul i32 [[CALL]], [[CALL]]
110; OVERIDE-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
111; OVERIDE-NEXT:    [[TMP3:%.*]] = mul i32 [[CALL]], [[TMP2]]
112; OVERIDE-NEXT:    [[TMP4:%.*]] = icmp sgt i32 [[CALL]], 0
113; OVERIDE-NEXT:    [[COND_FR:%.*]] = freeze i1 [[TMP4]]
114; OVERIDE-NEXT:    br i1 [[COND_FR]], label [[TMP5:%.*]], label [[COND_END_THREAD]]
115; OVERIDE:       5:
116; OVERIDE-NEXT:    br label [[COND_END_THREAD]]
117; OVERIDE:       cond.end.thread:
118; OVERIDE-NEXT:    [[TMP6:%.*]] = phi i32 [ [[TMP3]], [[COND_END]] ], [ [[TMP3]], [[TMP5]] ], [ 205962976, [[ENTRY:%.*]] ]
119; OVERIDE-NEXT:    [[TMP7:%.*]] = phi i32 [ 0, [[COND_END]] ], [ [[CALL]], [[TMP5]] ], [ 46, [[ENTRY]] ]
120; OVERIDE-NEXT:    [[TMP8:%.*]] = mul i32 [[TMP6]], [[TMP7]]
121; OVERIDE-NEXT:    [[CALL33:%.*]] = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i32 [[TMP8]])
122; OVERIDE-NEXT:    ret i32 0
123;
124entry:
125  %cmp = icmp eq i32 %argc, 2
126  br i1 %cmp, label %cond.true, label %cond.end
127
128cond.true:                                        ; preds = %entry
129  %arrayidx = getelementptr inbounds ptr, ptr %argv, i32 1
130  %0 = load ptr, ptr %arrayidx, align 4
131  %call = tail call i32 @atoi(ptr %0)
132  br label %cond.end
133
134cond.end:                                         ; preds = %entry, %cond.true
135  %cond = phi i32 [ %call, %cond.true ], [ 46, %entry ]
136  %1 = mul i32 %cond, %cond
137  %2 = mul i32 %1, %1
138  %3 = mul i32 %cond, %2
139  %4 = icmp sgt i32 %cond, 0
140  %spec.select = select i1 %4, i32 %cond, i32 0
141  %5 = mul i32 %3, %spec.select
142  %call33 = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i32 %5) #4
143  ret i32 0
144}
145declare i32 @atoi(ptr nocapture) local_unnamed_addr
146declare i32 @printf(ptr nocapture readonly, ...) local_unnamed_addr
147
148attributes #0 = { minsize optsize }
149attributes #1 = { optsize }
150
151