1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=1 -S < %s | FileCheck %s --check-prefix=HOIST
3 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=0 -S < %s | FileCheck %s --check-prefix=NOHOIST
4 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s --check-prefix=NOHOIST
6 ; This example is produced from a very basic C code:
12 ; void loop(int width) {
15 ; for(int i = 0; i < width - 1;+i) {
23 ; We have a choice here. We can either
24 ; * hoist the f0() call into loop header,
25 ; * which potentially makes loop rotation unprofitable since loop header might
26 ; have grown above certain threshold, and such unrotated loops will be
27 ; ignored by LoopVectorizer, preventing vectorization
28 ; * or loop rotation will succeed, resulting in some weird PHIs that will also
30 ; * or not hoist f0() call before performing loop rotation,
31 ; at the cost of potential code bloat and/or potentially successfully rotating
32 ; the loops, vectorizing them at the cost of compile time.
34 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
42 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
43 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
45 define void @_Z4loopi(i1 %cmp) {
46 ; HOIST-LABEL: @_Z4loopi(
48 ; HOIST-NEXT: br i1 [[CMP:%.*]], label [[RETURN:%.*]], label [[FOR_COND:%.*]]
50 ; HOIST-NEXT: [[CMP1:%.*]] = call i1 @gen1()
51 ; HOIST-NEXT: call void @f0()
52 ; HOIST-NEXT: br i1 [[CMP1]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
54 ; HOIST-NEXT: call void @f1()
55 ; HOIST-NEXT: br label [[FOR_COND]]
57 ; HOIST-NEXT: call void @f2()
58 ; HOIST-NEXT: br label [[RETURN]]
60 ; HOIST-NEXT: ret void
62 ; NOHOIST-LABEL: @_Z4loopi(
63 ; NOHOIST-NEXT: entry:
64 ; NOHOIST-NEXT: br i1 [[CMP:%.*]], label [[RETURN:%.*]], label [[FOR_COND:%.*]]
66 ; NOHOIST-NEXT: [[CMP1:%.*]] = call i1 @gen1()
67 ; NOHOIST-NEXT: br i1 [[CMP1]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
69 ; NOHOIST-NEXT: call void @f0()
70 ; NOHOIST-NEXT: call void @f1()
71 ; NOHOIST-NEXT: br label [[FOR_COND]]
73 ; NOHOIST-NEXT: call void @f0()
74 ; NOHOIST-NEXT: call void @f2()
75 ; NOHOIST-NEXT: br label [[RETURN]]
77 ; NOHOIST-NEXT: ret void
80 br i1 %cmp, label %if.then, label %if.end
89 %cmp1 = call i1 @gen1()
90 br i1 %cmp1, label %for.body, label %for.cond.cleanup
112 ; A example where only the branch instructions from %if.then2 and %if.end3 need
113 ; to be hoisted, which effectively replaces the original branch in %if.end and
114 ; only requires selects for PHIs in the successor.
115 define float @clamp_float_value(float %value, float %minimum_value, float %maximum_value) {
116 ; HOIST-LABEL: @clamp_float_value(
118 ; HOIST-NEXT: [[CMP:%.*]] = fcmp ogt float [[VALUE:%.*]], [[MAXIMUM_VALUE:%.*]]
119 ; HOIST-NEXT: [[CMP1:%.*]] = fcmp olt float [[VALUE]], [[MINIMUM_VALUE:%.*]]
120 ; HOIST-NEXT: [[MINIMUM_VALUE_VALUE:%.*]] = select i1 [[CMP1]], float [[MINIMUM_VALUE]], float [[VALUE]]
121 ; HOIST-NEXT: [[RETVAL_0:%.*]] = select i1 [[CMP]], float [[MAXIMUM_VALUE]], float [[MINIMUM_VALUE_VALUE]]
122 ; HOIST-NEXT: ret float [[RETVAL_0]]
124 ; NOHOIST-LABEL: @clamp_float_value(
125 ; NOHOIST-NEXT: entry:
126 ; NOHOIST-NEXT: [[CMP:%.*]] = fcmp ogt float [[VALUE:%.*]], [[MAXIMUM_VALUE:%.*]]
127 ; NOHOIST-NEXT: [[CMP1:%.*]] = fcmp olt float [[VALUE]], [[MINIMUM_VALUE:%.*]]
128 ; NOHOIST-NEXT: [[MINIMUM_VALUE_VALUE:%.*]] = select i1 [[CMP1]], float [[MINIMUM_VALUE]], float [[VALUE]]
129 ; NOHOIST-NEXT: [[RETVAL_0:%.*]] = select i1 [[CMP]], float [[MAXIMUM_VALUE]], float [[MINIMUM_VALUE_VALUE]]
130 ; NOHOIST-NEXT: ret float [[RETVAL_0]]
133 %cmp = fcmp ogt float %value, %maximum_value
134 br i1 %cmp, label %if.then, label %if.end
136 if.then: ; preds = %entry
139 if.end: ; preds = %entry
140 %cmp1 = fcmp olt float %value, %minimum_value
141 br i1 %cmp1, label %if.then2, label %if.end3
143 if.then2: ; preds = %if.end
146 if.end3: ; preds = %if.end
149 return: ; preds = %if.end3, %if.then2, %if.then
150 %retval.0 = phi float [ %maximum_value, %if.then ], [ %minimum_value, %if.then2 ], [ %value, %if.end3 ]