llvm.org GIT mirror llvm / 5f88af5
remove the ABCD and SSI passes. They don't have any clients that I'm aware of, aren't maintained, and LVI will be replacing their value. nlewycky approved this on irc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112355 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
15 changed file(s) with 0 addition(s) and 1836 deletion(s). Raw diff Collapse all Expand all
141141 (void) llvm::createDbgInfoPrinterPass();
142142 (void) llvm::createModuleDebugInfoPrinterPass();
143143 (void) llvm::createPartialInliningPass();
144 (void) llvm::createSSIPass();
145 (void) llvm::createSSIEverythingPass();
146144 (void) llvm::createGEPSplitterPass();
147 (void) llvm::createABCDPass();
148145 (void) llvm::createLintPass();
149146 (void) llvm::createSinkingPass();
150147 (void) llvm::createLowerAtomicPass();
306306
307307 //===----------------------------------------------------------------------===//
308308 //
309 // SSI - This pass converts instructions to Static Single Information form
310 // on demand.
311 //
312 FunctionPass *createSSIPass();
313
314 //===----------------------------------------------------------------------===//
315 //
316 // SSI - This pass converts every non-void instuction to Static Single
317 // Information form.
318 //
319 FunctionPass *createSSIEverythingPass();
320
321 //===----------------------------------------------------------------------===//
322 //
323309 // GEPSplitter - Split complex GEPs into simple ones
324310 //
325311 FunctionPass *createGEPSplitterPass();
326312
327313 //===----------------------------------------------------------------------===//
328314 //
329 // ABCD - Elimination of Array Bounds Checks on Demand
330 //
331 FunctionPass *createABCDPass();
332
333 //===----------------------------------------------------------------------===//
334 //
335315 // Sink - Code Sinking
336316 //
337317 FunctionPass *createSinkingPass();
+0
-93
include/llvm/Transforms/Utils/SSI.h less more
None //===------------------- SSI.h - Creates SSI Representation -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass converts a list of variables to the Static Single Information
10 // form. This is a program representation described by Scott Ananian in his
11 // Master Thesis: "The Static Single Information Form (1999)".
12 // We are building an on-demand representation, that is, we do not convert
13 // every single variable in the target function to SSI form. Rather, we receive
14 // a list of target variables that must be converted. We also do not
15 // completely convert a target variable to the SSI format. Instead, we only
16 // change the variable in the points where new information can be attached
17 // to its live range, that is, at branch points.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLVM_TRANSFORMS_UTILS_SSI_H
22 #define LLVM_TRANSFORMS_UTILS_SSI_H
23
24 #include "llvm/InstrTypes.h"
25 #include "llvm/Pass.h"
26 #include "llvm/ADT/DenseMap.h"
27 #include "llvm/ADT/SmallPtrSet.h"
28 #include "llvm/ADT/SmallVector.h"
29
30 namespace llvm {
31
32 class DominatorTree;
33 class PHINode;
34 class Instruction;
35 class CmpInst;
36
37 class SSI : public FunctionPass {
38 public:
39 static char ID; // Pass identification, replacement for typeid.
40 SSI() :
41 FunctionPass(ID) {
42 }
43
44 void getAnalysisUsage(AnalysisUsage &AU) const;
45
46 bool runOnFunction(Function&);
47
48 void createSSI(SmallVectorImpl &value);
49
50 private:
51 // Variables always live
52 DominatorTree *DT_;
53
54 // Stores variables created by SSI
55 SmallPtrSet created;
56
57 // Phis created by SSI
58 DenseMap phis;
59
60 // Sigmas created by SSI
61 DenseMap sigmas;
62
63 // Phi nodes that have a phi as operand and has to be fixed
64 SmallPtrSet phisToFix;
65
66 // List of definition points for every variable
67 DenseMap > defsites;
68
69 // Basic Block of the original definition of each variable
70 DenseMap value_original;
71
72 // Stack of last seen definition of a variable
73 DenseMap > value_stack;
74
75 void insertSigmaFunctions(SmallPtrSet &value);
76 void insertSigma(TerminatorInst *TI, Instruction *I);
77 void insertPhiFunctions(SmallPtrSet &value);
78 void renameInit(SmallPtrSet &value);
79 void rename(BasicBlock *BB);
80
81 void substituteUse(Instruction *I);
82 bool dominateAny(BasicBlock *BB, Instruction *value);
83 void fixPhis();
84
85 Instruction* getPositionPhi(PHINode *PN);
86 Instruction* getPositionSigma(PHINode *PN);
87
88 void init(SmallVectorImpl &value);
89 void clean();
90 };
91 } // end namespace
92 #endif
+0
-1103
lib/Transforms/Scalar/ABCD.cpp less more
None //===------- ABCD.cpp - Removes redundant conditional branches ------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass removes redundant branch instructions. This algorithm was
10 // described by Rastislav Bodik, Rajiv Gupta and Vivek Sarkar in their paper
11 // "ABCD: Eliminating Array Bounds Checks on Demand (2000)". The original
12 // Algorithm was created to remove array bound checks for strongly typed
13 // languages. This implementation expands the idea and removes any conditional
14 // branches that can be proved redundant, not only those used in array bound
15 // checks. With the SSI representation, each variable has a
16 // constraint. By analyzing these constraints we can prove that a branch is
17 // redundant. When a branch is proved redundant it means that
18 // one direction will always be taken; thus, we can change this branch into an
19 // unconditional jump.
20 // It is advisable to run SimplifyCFG and Aggressive Dead Code Elimination
21 // after ABCD to clean up the code.
22 // This implementation was created based on the implementation of the ABCD
23 // algorithm implemented for the compiler Jitrino.
24 //
25 //===----------------------------------------------------------------------===//
26
27 #define DEBUG_TYPE "abcd"
28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/ADT/OwningPtr.h"
30 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/ADT/Statistic.h"
32 #include "llvm/Constants.h"
33 #include "llvm/Function.h"
34 #include "llvm/Instructions.h"
35 #include "llvm/Pass.h"
36 #include "llvm/Support/raw_ostream.h"
37 #include "llvm/Support/Debug.h"
38 #include "llvm/Transforms/Scalar.h"
39 #include "llvm/Transforms/Utils/SSI.h"
40
41 using namespace llvm;
42
43 STATISTIC(NumBranchTested, "Number of conditional branches analyzed");
44 STATISTIC(NumBranchRemoved, "Number of conditional branches removed");
45
46 namespace {
47
48 class ABCD : public FunctionPass {
49 public:
50 static char ID; // Pass identification, replacement for typeid.
51 ABCD() : FunctionPass(ID) {}
52
53 void getAnalysisUsage(AnalysisUsage &AU) const {
54 AU.addRequired();
55 }
56
57 bool runOnFunction(Function &F);
58
59 private:
60 /// Keep track of whether we've modified the program yet.
61 bool modified;
62
63 enum ProveResult {
64 False = 0,
65 Reduced = 1,
66 True = 2
67 };
68
69 typedef ProveResult (*meet_function)(ProveResult, ProveResult);
70 static ProveResult max(ProveResult res1, ProveResult res2) {
71 return (ProveResult) std::max(res1, res2);
72 }
73 static ProveResult min(ProveResult res1, ProveResult res2) {
74 return (ProveResult) std::min(res1, res2);
75 }
76
77 class Bound {
78 public:
79 Bound(APInt v, bool upper) : value(v), upper_bound(upper) {}
80 Bound(const Bound &b, const APInt &cnst)
81 : value(b.value - cnst), upper_bound(b.upper_bound) {}
82
83 /// Test if Bound is an upper bound
84 bool isUpperBound() const { return upper_bound; }
85
86 /// Get the bitwidth of this bound
87 int32_t getBitWidth() const { return value.getBitWidth(); }
88
89 /// Creates a Bound incrementing the one received
90 static Bound createIncrement(const Bound &b) {
91 return Bound(b.isUpperBound() ? b.value+1 : b.value-1,
92 b.upper_bound);
93 }
94
95 /// Creates a Bound decrementing the one received
96 static Bound createDecrement(const Bound &b) {
97 return Bound(b.isUpperBound() ? b.value-1 : b.value+1,
98 b.upper_bound);
99 }
100
101 /// Test if two bounds are equal
102 static bool eq(const Bound *a, const Bound *b) {
103 if (!a || !b) return false;
104
105 assert(a->isUpperBound() == b->isUpperBound());
106 return a->value == b->value;
107 }
108
109 /// Test if val is less than or equal to Bound b
110 static bool leq(APInt val, const Bound &b) {
111 return b.isUpperBound() ? val.sle(b.value) : val.sge(b.value);
112 }
113
114 /// Test if Bound a is less then or equal to Bound
115 static bool leq(const Bound &a, const Bound &b) {
116 assert(a.isUpperBound() == b.isUpperBound());
117 return a.isUpperBound() ? a.value.sle(b.value) :
118 a.value.sge(b.value);
119 }
120
121 /// Test if Bound a is less then Bound b
122 static bool lt(const Bound &a, const Bound &b) {
123 assert(a.isUpperBound() == b.isUpperBound());
124 return a.isUpperBound() ? a.value.slt(b.value) :
125 a.value.sgt(b.value);
126 }
127
128 /// Test if Bound b is greater then or equal val
129 static bool geq(const Bound &b, const APInt &val) {
130 return leq(val, b);
131 }
132
133 private:
134 APInt value;
135 bool upper_bound;
136 };
137
138 /// This class is used to store results some parts of the graph,
139 /// so information does not need to be recalculated. The maximum false,
140 /// minimum true and minimum reduced results are stored
141 class MemoizedResultChart {
142 public:
143 MemoizedResultChart() {}
144 MemoizedResultChart(const MemoizedResultChart &other) {
145 if (other.max_false)
146 max_false.reset(new Bound(*other.max_false));
147 if (other.min_true)
148 min_true.reset(new Bound(*other.min_true));
149 if (other.min_reduced)
150 min_reduced.reset(new Bound(*other.min_reduced));
151 }
152
153 /// Returns the max false
154 const Bound *getFalse() const { return max_false.get(); }
155
156 /// Returns the min true
157 const Bound *getTrue() const { return min_true.get(); }
158
159 /// Returns the min reduced
160 const Bound *getReduced() const { return min_reduced.get(); }
161
162 /// Return the stored result for this bound
163 ProveResult getResult(const Bound &bound) const;
164
165 /// Stores a false found
166 void addFalse(const Bound &bound);
167
168 /// Stores a true found
169 void addTrue(const Bound &bound);
170
171 /// Stores a Reduced found
172 void addReduced(const Bound &bound);
173
174 /// Clears redundant reduced
175 /// If a min_true is smaller than a min_reduced then the min_reduced
176 /// is unnecessary and then removed. It also works for min_reduced
177 /// begin smaller than max_false.
178 void clearRedundantReduced();
179
180 void clear() {
181 max_false.reset();
182 min_true.reset();
183 min_reduced.reset();
184 }
185
186 private:
187 OwningPtr max_false, min_true, min_reduced;
188 };
189
190 /// This class stores the result found for a node of the graph,
191 /// so these results do not need to be recalculated, only searched for.
192 class MemoizedResult {
193 public:
194 /// Test if there is true result stored from b to a
195 /// that is less then the bound
196 bool hasTrue(Value *b, const Bound &bound) const {
197 const Bound *trueBound = map.lookup(b).getTrue();
198 return trueBound && Bound::leq(*trueBound, bound);
199 }
200
201 /// Test if there is false result stored from b to a
202 /// that is less then the bound
203 bool hasFalse(Value *b, const Bound &bound) const {
204 const Bound *falseBound = map.lookup(b).getFalse();
205 return falseBound && Bound::leq(*falseBound, bound);
206 }
207
208 /// Test if there is reduced result stored from b to a
209 /// that is less then the bound
210 bool hasReduced(Value *b, const Bound &bound) const {
211 const Bound *reducedBound = map.lookup(b).getReduced();
212 return reducedBound && Bound::leq(*reducedBound, bound);
213 }
214
215 /// Returns the stored bound for b
216 ProveResult getBoundResult(Value *b, const Bound &bound) {
217 return map[b].getResult(bound);
218 }
219
220 /// Clears the map
221 void clear() {
222 DenseMapIterator begin = map.begin();
223 DenseMapIterator end = map.end();
224 for (; begin != end; ++begin) {
225 begin->second.clear();
226 }
227 map.clear();
228 }
229
230 /// Stores the bound found
231 void updateBound(Value *b, const Bound &bound, const ProveResult res);
232
233 private:
234 // Maps a nod in the graph with its results found.
235 DenseMap map;
236 };
237
238 /// This class represents an edge in the inequality graph used by the
239 /// ABCD algorithm. An edge connects node v to node u with a value c if
240 /// we could infer a constraint v <= u + c in the source program.
241 class Edge {
242 public:
243 Edge(Value *V, APInt val, bool upper)
244 : vertex(V), value(val), upper_bound(upper) {}
245
246 Value *getVertex() const { return vertex; }
247 const APInt &getValue() const { return value; }
248 bool isUpperBound() const { return upper_bound; }
249
250 private:
251 Value *vertex;
252 APInt value;
253 bool upper_bound;
254 };
255
256 /// Weighted and Directed graph to represent constraints.
257 /// There is one type of constraint, a <= b + X, which will generate an
258 /// edge from b to a with weight X.
259 class InequalityGraph {
260 public:
261
262 /// Adds an edge from V_from to V_to with weight value
263 void addEdge(Value *V_from, Value *V_to, APInt value, bool upper);
264
265 /// Test if there is any edge from V in the upper direction
266 bool hasEdge(Value *V, bool upper) const;
267
268 /// Returns all edges pointed by vertex V
269 SmallVector getEdges(Value *V) const {
270 return graph.lookup(V);
271 }
272
273 /// Prints the graph in dot format.
274 /// Blue edges represent upper bound and Red lower bound.
275 void printGraph(raw_ostream &OS, Function &F) const {
276 printHeader(OS, F);
277 printBody(OS);
278 printFooter(OS);
279 }
280
281 /// Clear the graph
282 void clear() {
283 graph.clear();
284 }
285
286 private:
287 DenseMap > graph;
288
289 /// Prints the header of the dot file
290 void printHeader(raw_ostream &OS, Function &F) const;
291
292 /// Prints the footer of the dot file
293 void printFooter(raw_ostream &OS) const {
294 OS << "}\n";
295 }
296
297 /// Prints the body of the dot file
298 void printBody(raw_ostream &OS) const;
299
300 /// Prints vertex source to the dot file
301 void printVertex(raw_ostream &OS, Value *source) const;
302
303 /// Prints the edge to the dot file
304 void printEdge(raw_ostream &OS, Value *source, const Edge &edge) const;
305
306 void printName(raw_ostream &OS, Value *info) const;
307 };
308
309 /// Iterates through all BasicBlocks, if the Terminator Instruction
310 /// uses an Comparator Instruction, all operands of this comparator
311 /// are sent to be transformed to SSI. Only Instruction operands are
312 /// transformed.
313 void createSSI(Function &F);
314
315 /// Creates the graphs for this function.
316 /// It will look for all comparators used in branches, and create them.
317 /// These comparators will create constraints for any instruction as an
318 /// operand.
319 void executeABCD(Function &F);
320
321 /// Seeks redundancies in the comparator instruction CI.
322 /// If the ABCD algorithm can prove that the comparator CI always
323 /// takes one way, then the Terminator Instruction TI is substituted from
324 /// a conditional branch to a unconditional one.
325 /// This code basically receives a comparator, and verifies which kind of
326 /// instruction it is. Depending on the kind of instruction, we use different
327 /// strategies to prove its redundancy.
328 void seekRedundancy(ICmpInst *ICI, TerminatorInst *TI);
329
330 /// Substitutes Terminator Instruction TI, that is a conditional branch,
331 /// with one unconditional branch. Succ_edge determines if the new
332 /// unconditional edge will be the first or second edge of the former TI
333 /// instruction.
334 void removeRedundancy(TerminatorInst *TI, bool Succ_edge);
335
336 /// When an conditional branch is removed, the BasicBlock that is no longer
337 /// reachable will have problems in phi functions. This method fixes these
338 /// phis removing the former BasicBlock from the list of incoming BasicBlocks
339 /// of all phis. In case the phi remains with no predecessor it will be
340 /// marked to be removed later.
341 void fixPhi(BasicBlock *BB, BasicBlock *Succ);
342
343 /// Removes phis that have no predecessor
344 void removePhis();
345
346 /// Creates constraints for Instructions.
347 /// If the constraint for this instruction has already been created
348 /// nothing is done.
349 void createConstraintInstruction(Instruction *I);
350
351 /// Creates constraints for Binary Operators.
352 /// It will create constraints only for addition and subtraction,
353 /// the other binary operations are not treated by ABCD.
354 /// For additions in the form a = b + X and a = X + b, where X is a constant,
355 /// the constraint a <= b + X can be obtained. For this constraint, an edge
356 /// a->b with weight X is added to the lower bound graph, and an edge
357 /// b->a with weight -X is added to the upper bound graph.
358 /// Only subtractions in the format a = b - X is used by ABCD.
359 /// Edges are created using the same semantic as addition.
360 void createConstraintBinaryOperator(BinaryOperator *BO);
361
362 /// Creates constraints for Comparator Instructions.
363 /// Only comparators that have any of the following operators
364 /// are used to create constraints: >=, >, <=, <. And only if
365 /// at least one operand is an Instruction. In a Comparator Instruction
366 /// a op b, there will be 4 sigma functions a_t, a_f, b_t and b_f. Where
367 /// t and f represent sigma for operands in true and false branches. The
368 /// following constraints can be obtained. a_t <= a, a_f <= a, b_t <= b and
369 /// b_f <= b. There are two more constraints that depend on the operator.
370 /// For the operator <= : a_t <= b_t and b_f <= a_f-1
371 /// For the operator < : a_t <= b_t-1 and b_f <= a_f
372 /// For the operator >= : b_t <= a_t and a_f <= b_f-1
373 /// For the operator > : b_t <= a_t-1 and a_f <= b_f
374 void createConstraintCmpInst(ICmpInst *ICI, TerminatorInst *TI);
375
376 /// Creates constraints for PHI nodes.
377 /// In a PHI node a = phi(b,c) we can create the constraint
378 /// a<= max(b,c). With this constraint there will be the edges,
379 /// b->a and c->a with weight 0 in the lower bound graph, and the edges
380 /// a->b and a->c with weight 0 in the upper bound graph.
381 void createConstraintPHINode(PHINode *PN);
382
383 /// Given a binary operator, we are only interest in the case
384 /// that one operand is an Instruction and the other is a ConstantInt. In
385 /// this case the method returns true, otherwise false. It also obtains the
386 /// Instruction and ConstantInt from the BinaryOperator and returns it.
387 bool createBinaryOperatorInfo(BinaryOperator *BO, Instruction **I1,
388 Instruction **I2, ConstantInt **C1,
389 ConstantInt **C2);
390
391 /// This method creates a constraint between a Sigma and an Instruction.
392 /// These constraints are created as soon as we find a comparator that uses a
393 /// SSI variable.
394 void createConstraintSigInst(Instruction *I_op, BasicBlock *BB_succ_t,
395 BasicBlock *BB_succ_f, PHINode **SIG_op_t,
396 PHINode **SIG_op_f);
397
398 /// If PN_op1 and PN_o2 are different from NULL, create a constraint
399 /// PN_op2 -> PN_op1 with value. In case any of them is NULL, replace
400 /// with the respective V_op#, if V_op# is a ConstantInt.
401 void createConstraintSigSig(PHINode *SIG_op1, PHINode *SIG_op2,
402 ConstantInt *V_op1, ConstantInt *V_op2,
403 APInt value);
404
405 /// Returns the sigma representing the Instruction I in BasicBlock BB.
406 /// Returns NULL in case there is no sigma for this Instruction in this
407 /// Basic Block. This methods assume that sigmas are the first instructions
408 /// in a block, and that there can be only two sigmas in a block. So it will
409 /// only look on the first two instructions of BasicBlock BB.
410 PHINode *findSigma(BasicBlock *BB, Instruction *I);
411
412 /// Original ABCD algorithm to prove redundant checks.
413 /// This implementation works on any kind of inequality branch.
414 bool demandProve(Value *a, Value *b, int c, bool upper_bound);
415
416 /// Prove that distance between b and a is <= bound
417 ProveResult prove(Value *a, Value *b, const Bound &bound, unsigned level);
418
419 /// Updates the distance value for a and b
420 void updateMemDistance(Value *a, Value *b, const Bound &bound, unsigned level,
421 meet_function meet);
422
423 InequalityGraph inequality_graph;
424 MemoizedResult mem_result;
425 DenseMap active;
426 SmallPtrSet created;
427 SmallVector phis_to_remove;
428 };
429
430 } // end anonymous namespace.
431
432 char ABCD::ID = 0;
433 INITIALIZE_PASS(ABCD, "abcd",
434 "ABCD: Eliminating Array Bounds Checks on Demand",
435 false, false);
436
437 bool ABCD::runOnFunction(Function &F) {
438 modified = false;
439 createSSI(F);
440 executeABCD(F);
441 DEBUG(inequality_graph.printGraph(dbgs(), F));
442 removePhis();
443
444 inequality_graph.clear();
445 mem_result.clear();
446 active.clear();
447 created.clear();
448 phis_to_remove.clear();
449 return modified;
450 }
451
452 /// Iterates through all BasicBlocks, if the Terminator Instruction
453 /// uses an Comparator Instruction, all operands of this comparator
454 /// are sent to be transformed to SSI. Only Instruction operands are
455 /// transformed.
456 void ABCD::createSSI(Function &F) {
457 SSI *ssi = &getAnalysis();
458
459 SmallVector Insts;
460
461 for (Function::iterator begin = F.begin(), end = F.end();
462 begin != end; ++begin) {
463 BasicBlock *BB = begin;
464 TerminatorInst *TI = BB->getTerminator();
465 if (TI->getNumOperands() == 0)
466 continue;
467
468 if (ICmpInst *ICI = dyn_cast(TI->getOperand(0))) {
469 if (Instruction *I = dyn_cast(ICI->getOperand(0))) {
470 modified = true; // XXX: but yet createSSI might do nothing
471 Insts.push_back(I);
472 }
473 if (Instruction *I = dyn_cast(ICI->getOperand(1))) {
474 modified = true;
475 Insts.push_back(I);
476 }
477 }
478 }
479 ssi->createSSI(Insts);
480 }
481
482 /// Creates the graphs for this function.
483 /// It will look for all comparators used in branches, and create them.
484 /// These comparators will create constraints for any instruction as an
485 /// operand.
486 void ABCD::executeABCD(Function &F) {
487 for (Function::iterator begin = F.begin(), end = F.end();
488 begin != end; ++begin) {
489 BasicBlock *BB = begin;
490 TerminatorInst *TI = BB->getTerminator();
491 if (TI->getNumOperands() == 0)
492 continue;
493
494 ICmpInst *ICI = dyn_cast(TI->getOperand(0));
495 if (!ICI || !ICI->getOperand(0)->getType()->isIntegerTy())
496 continue;
497
498 createConstraintCmpInst(ICI, TI);
499 seekRedundancy(ICI, TI);
500 }
501 }
502
503 /// Seeks redundancies in the comparator instruction CI.
504 /// If the ABCD algorithm can prove that the comparator CI always
505 /// takes one way, then the Terminator Instruction TI is substituted from
506 /// a conditional branch to a unconditional one.
507 /// This code basically receives a comparator, and verifies which kind of
508 /// instruction it is. Depending on the kind of instruction, we use different
509 /// strategies to prove its redundancy.
510 void ABCD::seekRedundancy(ICmpInst *ICI, TerminatorInst *TI) {
511 CmpInst::Predicate Pred = ICI->getPredicate();
512
513 Value *source, *dest;
514 int distance1, distance2;
515 bool upper;
516
517 switch(Pred) {
518 case CmpInst::ICMP_SGT: // signed greater than
519 upper = false;
520 distance1 = 1;
521 distance2 = 0;
522 break;
523
524 case CmpInst::ICMP_SGE: // signed greater or equal
525 upper = false;
526 distance1 = 0;
527 distance2 = -1;
528 break;
529
530 case CmpInst::ICMP_SLT: // signed less than
531 upper = true;
532 distance1 = -1;
533 distance2 = 0;
534 break;
535
536 case CmpInst::ICMP_SLE: // signed less or equal
537 upper = true;
538 distance1 = 0;
539 distance2 = 1;
540 break;
541
542 default:
543 return;
544 }
545
546 ++NumBranchTested;
547 source = ICI->getOperand(0);
548 dest = ICI->getOperand(1);
549 if (demandProve(dest, source, distance1, upper)) {
550 removeRedundancy(TI, true);
551 } else if (demandProve(dest, source, distance2, !upper)) {
552 removeRedundancy(TI, false);
553 }
554 }
555
556 /// Substitutes Terminator Instruction TI, that is a conditional branch,
557 /// with one unconditional branch. Succ_edge determines if the new
558 /// unconditional edge will be the first or second edge of the former TI
559 /// instruction.
560 void ABCD::removeRedundancy(TerminatorInst *TI, bool Succ_edge) {
561 BasicBlock *Succ;
562 if (Succ_edge) {
563 Succ = TI->getSuccessor(0);
564 fixPhi(TI->getParent(), TI->getSuccessor(1));
565 } else {
566 Succ = TI->getSuccessor(1);
567 fixPhi(TI->getParent(), TI->getSuccessor(0));
568 }
569
570 BranchInst::Create(Succ, TI);
571 TI->eraseFromParent(); // XXX: invoke
572 ++NumBranchRemoved;
573 modified = true;
574 }
575
576 /// When an conditional branch is removed, the BasicBlock that is no longer
577 /// reachable will have problems in phi functions. This method fixes these
578 /// phis removing the former BasicBlock from the list of incoming BasicBlocks
579 /// of all phis. In case the phi remains with no predecessor it will be
580 /// marked to be removed later.
581 void ABCD::fixPhi(BasicBlock *BB, BasicBlock *Succ) {
582 BasicBlock::iterator begin = Succ->begin();
583 while (PHINode *PN = dyn_cast(begin++)) {
584 PN->removeIncomingValue(BB, false);
585 if (PN->getNumIncomingValues() == 0)
586 phis_to_remove.push_back(PN);
587 }
588 }
589
590 /// Removes phis that have no predecessor
591 void ABCD::removePhis() {
592 for (unsigned i = 0, e = phis_to_remove.size(); i != e; ++i) {
593 PHINode *PN = phis_to_remove[i];
594 PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
595 PN->eraseFromParent();
596 }
597 }
598
599 /// Creates constraints for Instructions.
600 /// If the constraint for this instruction has already been created
601 /// nothing is done.
602 void ABCD::createConstraintInstruction(Instruction *I) {
603 // Test if this instruction has not been created before
604 if (created.insert(I)) {
605 if (BinaryOperator *BO = dyn_cast(I)) {
606 createConstraintBinaryOperator(BO);
607 } else if (PHINode *PN = dyn_cast(I)) {
608 createConstraintPHINode(PN);
609 }
610 }
611 }
612
613 /// Creates constraints for Binary Operators.
614 /// It will create constraints only for addition and subtraction,
615 /// the other binary operations are not treated by ABCD.
616 /// For additions in the form a = b + X and a = X + b, where X is a constant,
617 /// the constraint a <= b + X can be obtained. For this constraint, an edge
618 /// a->b with weight X is added to the lower bound graph, and an edge
619 /// b->a with weight -X is added to the upper bound graph.
620 /// Only subtractions in the format a = b - X is used by ABCD.
621 /// Edges are created using the same semantic as addition.
622 void ABCD::createConstraintBinaryOperator(BinaryOperator *BO) {
623 Instruction *I1 = NULL, *I2 = NULL;
624 ConstantInt *CI1 = NULL, *CI2 = NULL;
625
626 // Test if an operand is an Instruction and the other is a Constant
627 if (!createBinaryOperatorInfo(BO, &I1, &I2, &CI1, &CI2))
628 return;
629
630 Instruction *I = 0;
631 APInt value;
632
633 switch (BO->getOpcode()) {
634 case Instruction::Add:
635 if (I1) {
636 I = I1;
637 value = CI2->getValue();
638 } else if (I2) {
639 I = I2;
640 value = CI1->getValue();
641 }
642 break;
643
644 case Instruction::Sub:
645 // Instructions like a = X-b, where X is a constant are not represented
646 // in the graph.
647 if (!I1)
648 return;
649
650 I = I1;
651 value = -CI2->getValue();
652 break;
653
654 default:
655 return;
656 }
657
658 inequality_graph.addEdge(I, BO, value, true);
659 inequality_graph.addEdge(BO, I, -value, false);
660 createConstraintInstruction(I);
661 }
662
663 /// Given a binary operator, we are only interest in the case
664 /// that one operand is an Instruction and the other is a ConstantInt. In
665 /// this case the method returns true, otherwise false. It also obtains the
666 /// Instruction and ConstantInt from the BinaryOperator and returns it.
667 bool ABCD::createBinaryOperatorInfo(BinaryOperator *BO, Instruction **I1,
668 Instruction **I2, ConstantInt **C1,
669 ConstantInt **C2) {
670 Value *op1 = BO->getOperand(0);
671 Value *op2 = BO->getOperand(1);
672
673 if ((*I1 = dyn_cast(op1))) {
674 if ((*C2 = dyn_cast(op2)))
675 return true; // First is Instruction and second ConstantInt
676
677 return false; // Both are Instruction
678 } else {
679 if ((*C1 = dyn_cast(op1)) &&
680 (*I2 = dyn_cast(op2)))
681 return true; // First is ConstantInt and second Instruction
682
683 return false; // Both are not Instruction
684 }
685 }
686
687 /// Creates constraints for Comparator Instructions.
688 /// Only comparators that have any of the following operators
689 /// are used to create constraints: >=, >, <=, <. And only if
690 /// at least one operand is an Instruction. In a Comparator Instruction
691 /// a op b, there will be 4 sigma functions a_t, a_f, b_t and b_f. Where
692 /// t and f represent sigma for operands in true and false branches. The
693 /// following constraints can be obtained. a_t <= a, a_f <= a, b_t <= b and
694 /// b_f <= b. There are two more constraints that depend on the operator.
695 /// For the operator <= : a_t <= b_t and b_f <= a_f-1
696 /// For the operator < : a_t <= b_t-1 and b_f <= a_f
697 /// For the operator >= : b_t <= a_t and a_f <= b_f-1
698 /// For the operator > : b_t <= a_t-1 and a_f <= b_f
699 void ABCD::createConstraintCmpInst(ICmpInst *ICI, TerminatorInst *TI) {
700 Value *V_op1 = ICI->getOperand(0);
701 Value *V_op2 = ICI->getOperand(1);
702
703 if (!V_op1->getType()->isIntegerTy())
704 return;
705
706 Instruction *I_op1 = dyn_cast(V_op1);
707 Instruction *I_op2 = dyn_cast(V_op2);
708
709 // Test if at least one operand is an Instruction
710 if (!I_op1 && !I_op2)
711 return;
712
713 BasicBlock *BB_succ_t = TI->getSuccessor(0);
714 BasicBlock *BB_succ_f = TI->getSuccessor(1);
715
716 PHINode *SIG_op1_t = NULL, *SIG_op1_f = NULL,
717 *SIG_op2_t = NULL, *SIG_op2_f = NULL;
718
719 createConstraintSigInst(I_op1, BB_succ_t, BB_succ_f, &SIG_op1_t, &SIG_op1_f);
720 createConstraintSigInst(I_op2, BB_succ_t, BB_succ_f, &SIG_op2_t, &SIG_op2_f);
721
722 int32_t width = cast(V_op1->getType())->getBitWidth();
723 APInt MinusOne = APInt::getAllOnesValue(width);
724 APInt Zero = APInt::getNullValue(width);
725
726 CmpInst::Predicate Pred = ICI->getPredicate();
727 ConstantInt *CI1 = dyn_cast(V_op1);
728 ConstantInt *CI2 = dyn_cast(V_op2);
729 switch (Pred) {
730 case CmpInst::ICMP_SGT: // signed greater than
731 createConstraintSigSig(SIG_op2_t, SIG_op1_t, CI2, CI1, MinusOne);
732 createConstraintSigSig(SIG_op1_f, SIG_op2_f, CI1, CI2, Zero);
733 break;
734
735 case CmpInst::ICMP_SGE: // signed greater or equal
736 createConstraintSigSig(SIG_op2_t, SIG_op1_t, CI2, CI1, Zero);
737 createConstraintSigSig(SIG_op1_f, SIG_op2_f, CI1, CI2, MinusOne);
738 break;
739
740 case CmpInst::ICMP_SLT: // signed less than
741 createConstraintSigSig(SIG_op1_t, SIG_op2_t, CI1, CI2, MinusOne);
742 createConstraintSigSig(SIG_op2_f, SIG_op1_f, CI2, CI1, Zero);
743 break;
744
745 case CmpInst::ICMP_SLE: // signed less or equal
746 createConstraintSigSig(SIG_op1_t, SIG_op2_t, CI1, CI2, Zero);
747 createConstraintSigSig(SIG_op2_f, SIG_op1_f, CI2, CI1, MinusOne);
748 break;
749
750 default:
751 break;
752 }
753
754 if (I_op1)
755 createConstraintInstruction(I_op1);
756 if (I_op2)
757 createConstraintInstruction(I_op2);
758 }
759
760 /// Creates constraints for PHI nodes.
761 /// In a PHI node a = phi(b,c) we can create the constraint
762 /// a<= max(b,c). With this constraint there will be the edges,
763 /// b->a and c->a with weight 0 in the lower bound graph, and the edges
764 /// a->b and a->c with weight 0 in the upper bound graph.
765 void ABCD::createConstraintPHINode(PHINode *PN) {
766 // FIXME: We really want to disallow sigma nodes, but I don't know the best
767 // way to detect the other than this.
768 if (PN->getNumOperands() == 2) return;
769
770 int32_t width = cast(PN->getType())->getBitWidth();
771 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
772 Value *V = PN->getIncomingValue(i);
773 if (Instruction *I = dyn_cast(V)) {
774 createConstraintInstruction(I);
775 }
776 inequality_graph.addEdge(V, PN, APInt(width, 0), true);
777 inequality_graph.addEdge(V, PN, APInt(width, 0), false);
778 }
779 }
780
781 /// This method creates a constraint between a Sigma and an Instruction.
782 /// These constraints are created as soon as we find a comparator that uses a
783 /// SSI variable.
784 void ABCD::createConstraintSigInst(Instruction *I_op, BasicBlock *BB_succ_t,
785 BasicBlock *BB_succ_f, PHINode **SIG_op_t,
786 PHINode **SIG_op_f) {
787 *SIG_op_t = findSigma(BB_succ_t, I_op);
788 *SIG_op_f = findSigma(BB_succ_f, I_op);
789
790 if (*SIG_op_t) {
791 int32_t width = cast((*SIG_op_t)->getType())->getBitWidth();
792 inequality_graph.addEdge(I_op, *SIG_op_t, APInt(width, 0), true);
793 inequality_graph.addEdge(*SIG_op_t, I_op, APInt(width, 0), false);
794 }
795 if (*SIG_op_f) {
796 int32_t width = cast((*SIG_op_f)->getType())->getBitWidth();
797 inequality_graph.addEdge(I_op, *SIG_op_f, APInt(width, 0), true);
798 inequality_graph.addEdge(*SIG_op_f, I_op, APInt(width, 0), false);
799 }
800 }
801
802 /// If PN_op1 and PN_o2 are different from NULL, create a constraint
803 /// PN_op2 -> PN_op1 with value. In case any of them is NULL, replace
804 /// with the respective V_op#, if V_op# is a ConstantInt.
805 void ABCD::createConstraintSigSig(PHINode *SIG_op1, PHINode *SIG_op2,
806 ConstantInt *V_op1, ConstantInt *V_op2,
807 APInt value) {
808 if (SIG_op1 && SIG_op2) {
809 inequality_graph.addEdge(SIG_op2, SIG_op1, value, true);
810 inequality_graph.addEdge(SIG_op1, SIG_op2, -value, false);
811 } else if (SIG_op1 && V_op2) {
812 inequality_graph.addEdge(V_op2, SIG_op1, value, true);
813 inequality_graph.addEdge(SIG_op1, V_op2, -value, false);
814 } else if (SIG_op2 && V_op1) {
815 inequality_graph.addEdge(SIG_op2, V_op1, value, true);
816 inequality_graph.addEdge(V_op1, SIG_op2, -value, false);
817 }
818 }
819
820 /// Returns the sigma representing the Instruction I in BasicBlock BB.
821 /// Returns NULL in case there is no sigma for this Instruction in this
822 /// Basic Block. This methods assume that sigmas are the first instructions
823 /// in a block, and that there can be only two sigmas in a block. So it will
824 /// only look on the first two instructions of BasicBlock BB.
825 PHINode *ABCD::findSigma(BasicBlock *BB, Instruction *I) {
826 // BB has more than one predecessor, BB cannot have sigmas.
827 if (I == NULL || BB->getSinglePredecessor() == NULL)
828 return NULL;
829
830 BasicBlock::iterator begin = BB->begin();
831 BasicBlock::iterator end = BB->end();
832
833 for (unsigned i = 0; i < 2 && begin != end; ++i, ++begin) {
834 Instruction *I_succ = begin;
835 if (PHINode *PN = dyn_cast(I_succ))
836 if (PN->getIncomingValue(0) == I)
837 return PN;
838 }
839
840 return NULL;
841 }
842
843 /// Original ABCD algorithm to prove redundant checks.
844 /// This implementation works on any kind of inequality branch.
845 bool ABCD::demandProve(Value *a, Value *b, int c, bool upper_bound) {
846 int32_t width = cast(a->getType())->getBitWidth();
847 Bound bound(APInt(width, c), upper_bound);
848
849 mem_result.clear();
850 active.clear();
851
852 ProveResult res = prove(a, b, bound, 0);
853 return res != False;
854 }
855
856 /// Prove that distance between b and a is <= bound
857 ABCD::ProveResult ABCD::prove(Value *a, Value *b, const Bound &bound,
858 unsigned level) {
859 // if (C[b-a<=e] == True for some e <= bound
860 // Same or stronger difference was already proven
861 if (mem_result.hasTrue(b, bound))
862 return True;
863
864 // if (C[b-a<=e] == False for some e >= bound
865 // Same or weaker difference was already disproved
866 if (mem_result.hasFalse(b, bound))
867 return False;
868
869 // if (C[b-a<=e] == Reduced for some e <= bound
870 // b is on a cycle that was reduced for same or stronger difference
871 if (mem_result.hasReduced(b, bound))
872 return Reduced;
873
874 // traversal reached the source vertex
875 if (a == b && Bound::geq(bound, APInt(bound.getBitWidth(), 0, true)))
876 return True;
877
878 // if b has no predecessor then fail
879 if (!inequality_graph.hasEdge(b, bound.isUpperBound()))
880 return False;
881
882 // a cycle was encountered
883 if (active.count(b)) {
884 if (Bound::leq(*active.lookup(b), bound))
885 return Reduced; // a "harmless" cycle
886
887 return False; // an amplifying cycle
888 }
889
890 active[b] = &bound;
891 PHINode *PN = dyn_cast(b);
892
893 // Test if a Value is a Phi. If it is a PHINode with more than 1 incoming
894 // value, then it is a phi, if it has 1 incoming value it is a sigma.
895 if (PN && PN->getNumIncomingValues() > 1)
896 updateMemDistance(a, b, bound, level, min);
897 else
898 updateMemDistance(a, b, bound, level, max);
899
900 active.erase(b);
901
902 ABCD::ProveResult res = mem_result.getBoundResult(b, bound);
903 return res;
904 }
905
906 /// Updates the distance value for a and b
907 void ABCD::updateMemDistance(Value *a, Value *b, const Bound &bound,
908 unsigned level, meet_function meet) {
909 ABCD::ProveResult res = (meet == max) ? False : True;
910
911 SmallVector Edges = inequality_graph.getEdges(b);
912 SmallVector::iterator begin = Edges.begin(), end = Edges.end();
913
914 for (; begin != end ; ++begin) {
915 if (((res >= Reduced) && (meet == max)) ||
916 ((res == False) && (meet == min))) {
917 break;
918 }
919 const Edge &in = *begin;
920 if (in.isUpperBound() == bound.isUpperBound()) {
921 Value *succ = in.getVertex();
922 res = meet(res, prove(a, succ, Bound(bound, in.getValue()),
923 level+1));
924 }
925 }
926
927 mem_result.updateBound(b, bound, res);
928 }
929
930 /// Return the stored result for this bound
931 ABCD::ProveResult ABCD::MemoizedResultChart::getResult(const Bound &bound)const{
932 if (max_false && Bound::leq(bound, *max_false))
933 return False;
934 if (min_true && Bound::leq(*min_true, bound))
935 return True;
936 if (min_reduced && Bound::leq(*min_reduced, bound))
937 return Reduced;
938 return False;
939 }
940
941 /// Stores a false found
942 void ABCD::MemoizedResultChart::addFalse(const Bound &bound) {
943 if (!max_false || Bound::leq(*max_false, bound))
944 max_false.reset(new Bound(bound));
945
946 if (Bound::eq(max_false.get(), min_reduced.get()))
947 min_reduced.reset(new Bound(Bound::createIncrement(*min_reduced)));
948 if (Bound::eq(max_false.get(), min_true.get()))
949 min_true.reset(new Bound(Bound::createIncrement(*min_true)));
950 if (Bound::eq(min_reduced.get(), min_true.get()))
951 min_reduced.reset();
952 clearRedundantReduced();
953 }
954
955 /// Stores a true found
956 void ABCD::MemoizedResultChart::addTrue(const Bound &bound) {
957 if (!min_true || Bound::leq(bound, *min_true))
958 min_true.reset(new Bound(bound));
959
960 if (Bound::eq(min_true.get(), min_reduced.get()))
961 min_reduced.reset(new Bound(Bound::createDecrement(*min_reduced)));
962 if (Bound::eq(min_true.get(), max_false.get()))
963 max_false.reset(new Bound(Bound::createDecrement(*max_false)));
964 if (Bound::eq(max_false.get(), min_reduced.get()))
965 min_reduced.reset();
966 clearRedundantReduced();
967 }
968
969 /// Stores a Reduced found
970 void ABCD::MemoizedResultChart::addReduced(const Bound &bound) {
971 if (!min_reduced || Bound::leq(bound, *min_reduced))
972 min_reduced.reset(new Bound(bound));
973
974 if (Bound::eq(min_reduced.get(), min_true.get()))
975 min_true.reset(new Bound(Bound::createIncrement(*min_true)));
976 if (Bound::eq(min_reduced.get(), max_false.get()))
977 max_false.reset(new Bound(Bound::createDecrement(*max_false)));
978 }
979
980 /// Clears redundant reduced
981 /// If a min_true is smaller than a min_reduced then the min_reduced
982 /// is unnecessary and then removed. It also works for min_reduced
983 /// begin smaller than max_false.
984 void ABCD::MemoizedResultChart::clearRedundantReduced() {
985 if (min_true && min_reduced && Bound::lt(*min_true, *min_reduced))
986 min_reduced.reset();
987 if (max_false && min_reduced && Bound::lt(*min_reduced, *max_false))
988 min_reduced.reset();
989 }
990
991 /// Stores the bound found
992 void ABCD::MemoizedResult::updateBound(Value *b, const Bound &bound,
993 const ProveResult res) {
994 if (res == False) {
995 map[b].addFalse(bound);
996 } else if (res == True) {
997 map[b].addTrue(bound);
998 } else {
999 map[b].addReduced(bound);
1000 }
1001 }
1002
1003 /// Adds an edge from V_from to V_to with weight value
1004 void ABCD::InequalityGraph::addEdge(Value *V_to, Value *V_from,
1005 APInt value, bool upper) {
1006 assert(V_from->getType() == V_to->getType());
1007 assert(cast(V_from->getType())->getBitWidth() ==
1008 value.getBitWidth());
1009
1010 graph[V_from].push_back(Edge(V_to, value, upper));
1011 }
1012
1013 /// Test if there is any edge from V in the upper direction
1014 bool ABCD::InequalityGraph::hasEdge(Value *V, bool upper) const {
1015 SmallVector it = graph.lookup(V);
1016
1017 SmallVector::iterator begin = it.begin();
1018 SmallVector::iterator end = it.end();
1019 for (; begin != end; ++begin) {
1020 if (begin->isUpperBound() == upper) {
1021 return true;
1022 }
1023 }
1024 return false;
1025 }
1026
1027 /// Prints the header of the dot file
1028 void ABCD::InequalityGraph::printHeader(raw_ostream &OS, Function &F) const {
1029 OS << "digraph dotgraph {\n";
1030 OS << "label=\"Inequality Graph for \'";
1031 OS << F.getNameStr() << "\' function\";\n";
1032 OS << "node [shape=record,fontname=\"Times-Roman\",fontsize=14];\n";
1033 }
1034
1035 /// Prints the body of the dot file
1036 void ABCD::InequalityGraph::printBody(raw_ostream &OS) const {
1037 DenseMap >::const_iterator begin =
1038 graph.begin(), end = graph.end();
1039
1040 for (; begin != end ; ++begin) {
1041 SmallVector::const_iterator begin_par =
1042 begin->second.begin(), end_par = begin->second.end();
1043 Value *source = begin->first;
1044
1045 printVertex(OS, source);
1046
1047 for (; begin_par != end_par ; ++begin_par) {
1048 const Edge &edge = *begin_par;
1049 printEdge(OS, source, edge);
1050 }
1051 }
1052 }
1053
1054 /// Prints vertex source to the dot file
1055 ///
1056 void ABCD::InequalityGraph::printVertex(raw_ostream &OS, Value *source) const {
1057 OS << "\"";
1058 printName(OS, source);
1059 OS << "\"";
1060 OS << " [label=\"{";
1061 printName(OS, source);
1062 OS << "}\"];\n";
1063 }
1064
1065 /// Prints the edge to the dot file
1066 void ABCD::InequalityGraph::printEdge(raw_ostream &OS, Value *source,
1067 const Edge &edge) const {
1068 Value *dest = edge.getVertex();
1069 APInt value = edge.getValue();
1070 bool upper = edge.isUpperBound();
1071
1072 OS << "\"";
1073 printName(OS, source);
1074 OS << "\"";
1075 OS << " -> ";
1076 OS << "\"";
1077 printName(OS, dest);
1078 OS << "\"";
1079 OS << " [label=\"" << value << "\"";
1080 if (upper) {
1081 OS << "color=\"blue\"";
1082 } else {
1083 OS << "color=\"red\"";
1084 }
1085 OS << "];\n";
1086 }
1087
1088 void ABCD::InequalityGraph::printName(raw_ostream &OS, Value *info) const {
1089 if (ConstantInt *CI = dyn_cast(info)) {
1090 OS << *CI;
1091 } else {
1092 if (!info->hasName()) {
1093 info->setName("V");
1094 }
1095 OS << info->getNameStr();
1096 }
1097 }
1098
1099 /// createABCDPass - The public interface to this file...
1100 FunctionPass *llvm::createABCDPass() {
1101 return new ABCD();
1102 }
0 add_llvm_library(LLVMScalarOpts
1 ABCD.cpp
21 ADCE.cpp
32 BasicBlockPlacement.cpp
43 CodeGenPrepare.cpp
1919 Mem2Reg.cpp
2020 PromoteMemoryToRegister.cpp
2121 SSAUpdater.cpp
22 SSI.cpp
2322 SimplifyCFG.cpp
2423 UnifyFunctionExitNodes.cpp
2524 ValueMapper.cpp
+0
-433
lib/Transforms/Utils/SSI.cpp less more
None //===------------------- SSI.cpp - Creates SSI Representation -------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass converts a list of variables to the Static Single Information
10 // form. This is a program representation described by Scott Ananian in his
11 // Master Thesis: "The Static Single Information Form (1999)".
12 // We are building an on-demand representation, that is, we do not convert
13 // every single variable in the target function to SSI form. Rather, we receive
14 // a list of target variables that must be converted. We also do not
15 // completely convert a target variable to the SSI format. Instead, we only
16 // change the variable in the points where new information can be attached
17 // to its live range, that is, at branch points.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #define DEBUG_TYPE "ssi"
22
23 #include "llvm/Transforms/Scalar.h"
24 #include "llvm/Transforms/Utils/SSI.h"
25 #include "llvm/ADT/Statistic.h"
26 #include "llvm/Analysis/Dominators.h"
27
28 using namespace llvm;
29
30 static const std::string SSI_PHI = "SSI_phi";
31 static const std::string SSI_SIG = "SSI_sigma";
32
33 STATISTIC(NumSigmaInserted, "Number of sigma functions inserted");
34 STATISTIC(NumPhiInserted, "Number of phi functions inserted");
35
36 void SSI::getAnalysisUsage(AnalysisUsage &AU) const {
37 AU.addRequiredTransitive();
38 AU.addRequiredTransitive();
39 AU.setPreservesAll();
40 }
41
42 bool SSI::runOnFunction(Function &F) {
43 DT_ = &getAnalysis();
44 return false;
45 }
46
47 /// This methods creates the SSI representation for the list of values
48 /// received. It will only create SSI representation if a value is used
49 /// to decide a branch. Repeated values are created only once.
50 ///
51 void SSI::createSSI(SmallVectorImpl &value) {
52 init(value);
53
54 SmallPtrSet needConstruction;
55 for (SmallVectorImpl::iterator I = value.begin(),
56 E = value.end(); I != E; ++I)
57 if (created.insert(*I))
58 needConstruction.insert(*I);
59
60 insertSigmaFunctions(needConstruction);
61
62 // Test if there is a need to transform to SSI
63 if (!needConstruction.empty()) {
64 insertPhiFunctions(needConstruction);
65 renameInit(needConstruction);
66 rename(DT_->getRoot());
67 fixPhis();
68 }
69
70 clean();
71 }
72
73 /// Insert sigma functions (a sigma function is a phi function with one
74 /// operator)
75 ///
76 void SSI::insertSigmaFunctions(SmallPtrSet &value) {
77 for (SmallPtrSet::iterator I = value.begin(),
78 E = value.end(); I != E; ++I) {
79 for (Value::use_iterator begin = (*I)->use_begin(),
80 end = (*I)->use_end(); begin != end; ++begin) {
81 // Test if the Use of the Value is in a comparator
82 if (CmpInst *CI = dyn_cast(*begin)) {
83 // Iterates through all uses of CmpInst
84 for (Value::use_iterator begin_ci = CI->use_begin(),
85 end_ci = CI->use_end(); begin_ci != end_ci; ++begin_ci) {
86 // Test if any use of CmpInst is in a Terminator
87 if (TerminatorInst *TI = dyn_cast(*begin_ci)) {
88 insertSigma(TI, *I);
89 }
90 }
91 }
92 }
93 }
94 }
95
96 /// Inserts Sigma Functions in every BasicBlock successor to Terminator
97 /// Instruction TI. All inserted Sigma Function are related to Instruction I.
98 ///
99 void SSI::insertSigma(TerminatorInst *TI, Instruction *I) {
100 // Basic Block of the Terminator Instruction
101 BasicBlock *BB = TI->getParent();
102 for (unsigned i = 0, e = TI->getNumSuccessors(); i < e; ++i) {
103 // Next Basic Block
104 BasicBlock *BB_next = TI->getSuccessor(i);
105 if (BB_next != BB &&
106 BB_next->getSinglePredecessor() != NULL &&
107 dominateAny(BB_next, I)) {
108 PHINode *PN = PHINode::Create(I->getType(), SSI_SIG, BB_next->begin());
109 PN->addIncoming(I, BB);
110 sigmas[PN] = I;
111 created.insert(PN);
112 defsites[I].push_back(BB_next);
113 ++NumSigmaInserted;
114 }
115 }
116 }
117
118 /// Insert phi functions when necessary
119 ///
120 void SSI::insertPhiFunctions(SmallPtrSet &value) {
121 DominanceFrontier *DF = &getAnalysis();
122 for (SmallPtrSet::iterator I = value.begin(),
123 E = value.end(); I != E; ++I) {
124 // Test if there were any sigmas for this variable
125 SmallPtrSet BB_visited;
126
127 // Insert phi functions if there is any sigma function
128 while (!defsites[*I].empty()) {
129
130 BasicBlock *BB = defsites[*I].back();
131
132 defsites[*I].pop_back();
133 DominanceFrontier::iterator DF_BB = DF->find(BB);
134
135 // The BB is unreachable. Skip it.
136 if (DF_BB == DF->end())
137 continue;
138
139 // Iterates through all the dominance frontier of BB
140 for (std::set::iterator DF_BB_begin =
141 DF_BB->second.begin(), DF_BB_end = DF_BB->second.end();
142 DF_BB_begin != DF_BB_end; ++DF_BB_begin) {
143 BasicBlock *BB_dominated = *DF_BB_begin;
144
145 // Test if has not yet visited this node and if the
146 // original definition dominates this node
147 if (BB_visited.insert(BB_dominated) &&
148 DT_->properlyDominates(value_original[*I], BB_dominated) &&
149 dominateAny(BB_dominated, *I)) {
150 PHINode *PN = PHINode::Create(
151 (*I)->getType(), SSI_PHI, BB_dominated->begin());
152 phis.insert(std::make_pair(PN, *I));
153 created.insert(PN);
154
155 defsites[*I].push_back(BB_dominated);
156 ++NumPhiInserted;
157 }
158 }
159 }
160 BB_visited.clear();
161 }
162 }
163
164 /// Some initialization for the rename part
165 ///
166 void SSI::renameInit(SmallPtrSet &value) {
167 for (SmallPtrSet::iterator I = value.begin(),
168 E = value.end(); I != E; ++I)
169 value_stack[*I].push_back(*I);
170 }
171
172 /// Renames all variables in the specified BasicBlock.
173 /// Only variables that need to be rename will be.
174 ///
175 void SSI::rename(BasicBlock *BB) {
176 SmallPtrSet defined;
177
178 // Iterate through instructions and make appropriate renaming.
179 // For SSI_PHI (b = PHI()), store b at value_stack as a new
180 // definition of the variable it represents.
181 // For SSI_SIG (b = PHI(a)), substitute a with the current
182 // value of a, present in the value_stack.
183 // Then store bin the value_stack as the new definition of a.
184 // For all other instructions (b = OP(a, c, d, ...)), we need to substitute
185 // all operands with its current value, present in value_stack.
186 for (BasicBlock::iterator begin = BB->begin(), end = BB->end();
187 begin != end; ++begin) {
188 Instruction *I = begin;
189 if (PHINode *PN = dyn_cast(I)) { // Treat PHI functions
190 Instruction* position;
191
192 // Treat SSI_PHI
193 if ((position = getPositionPhi(PN))) {
194 value_stack[position].push_back(PN);
195 defined.insert(position);
196 // Treat SSI_SIG
197 } else if ((position = getPositionSigma(PN))) {
198 substituteUse(I);
199 value_stack[position].push_back(PN);
200 defined.insert(position);
201 }
202
203 // Treat all other PHI functions
204 else {
205 substituteUse(I);
206 }
207 }
208
209 // Treat all other functions
210 else {
211 substituteUse(I);
212 }
213 }
214
215 // This loop iterates in all BasicBlocks that are successors of the current
216 // BasicBlock. For each SSI_PHI instruction found, insert an operand.
217 // This operand is the current operand in value_stack for the variable
218 // in "position". And the BasicBlock this operand represents is the current
219 // BasicBlock.
220 for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) {
221 BasicBlock *BB_succ = *SI;
222
223 for (BasicBlock::iterator begin = BB_succ->begin(),
224 notPhi = BB_succ->getFirstNonPHI(); begin != *notPhi; ++begin) {
225 Instruction *I = begin;
226 PHINode *PN = dyn_cast(I);
227 Instruction* position;
228 if (PN && ((position = getPositionPhi(PN)))) {
229 PN->addIncoming(value_stack[position].back(), BB);
230 }
231 }
232 }
233
234 // This loop calls rename on all children from this block. This time children
235 // refers to a successor block in the dominance tree.
236 DomTreeNode *DTN = DT_->getNode(BB);
237 for (DomTreeNode::iterator begin = DTN->begin(), end = DTN->end();
238 begin != end; ++begin) {
239 DomTreeNodeBase *DTN_children = *begin;
240 BasicBlock *BB_children = DTN_children->getBlock();
241 rename(BB_children);
242 }
243
244 // Now we remove all inserted definitions of a variable from the top of
245 // the stack leaving the previous one as the top.
246 for (SmallPtrSet::iterator DI = defined.begin(),
247 DE = defined.end(); DI != DE; ++DI)
248 value_stack[*DI].pop_back();
249 }
250
251 /// Substitute any use in this instruction for the last definition of
252 /// the variable
253 ///
254 void SSI::substituteUse(Instruction *I) {
255 for (unsigned i = 0, e = I->getNumOperands(); i < e; ++i) {
256 Value *operand = I->getOperand(i);
257 for (DenseMap >::iterator
258 VI = value_stack.begin(), VE = value_stack.end(); VI != VE; ++VI) {
259 if (operand == VI->second.front() &&
260 I != VI->second.back()) {
261 PHINode *PN_I = dyn_cast(I);
262 PHINode *PN_vs = dyn_cast(VI->second.back());
263
264 // If a phi created in a BasicBlock is used as an operand of another
265 // created in the same BasicBlock, this step marks this second phi,
266 // to fix this issue later. It cannot be fixed now, because the
267 // operands of the first phi are not final yet.
268 if (PN_I && PN_vs &&
269 VI->second.back()->getParent() == I->getParent()) {
270
271 phisToFix.insert(PN_I);
272 }
273
274 I->setOperand(i, VI->second.back());
275 break;
276 }
277 }
278 }
279 }
280
281 /// Test if the BasicBlock BB dominates any use or definition of value.
282 /// If it dominates a phi instruction that is on the same BasicBlock,
283 /// that does not count.
284 ///
285 bool SSI::dominateAny(BasicBlock *BB, Instruction *value) {
286 for (Value::use_iterator begin = value->use_begin(),
287 end = value->use_end(); begin != end; ++begin) {
288 Instruction *I = cast(*begin);
289 BasicBlock *BB_father = I->getParent();
290 if (BB == BB_father && isa(I))
291 continue;
292 if (DT_->dominates(BB, BB_father)) {
293 return true;
294 }
295 }
296 return false;
297 }
298
299 /// When there is a phi node that is created in a BasicBlock and it is used
300 /// as an operand of another phi function used in the same BasicBlock,
301 /// LLVM looks this as an error. So on the second phi, the first phi is called
302 /// P and the BasicBlock it incomes is B. This P will be replaced by the value
303 /// it has for BasicBlock B. It also includes undef values for predecessors
304 /// that were not included in the phi.
305 ///
306 void SSI::fixPhis() {
307 for (SmallPtrSet::iterator begin = phisToFix.begin(),
308 end = phisToFix.end(); begin != end; ++begin) {
309 PHINode *PN = *begin;
310 for (unsigned i = 0, e = PN->getNumIncomingValues(); i < e; ++i) {
311 PHINode *PN_father = dyn_cast(PN->getIncomingValue(i));
312 if (PN_father && PN->getParent() == PN_father->getParent() &&
313 !DT_->dominates(PN->getParent(), PN->getIncomingBlock(i))) {
314 BasicBlock *BB = PN->getIncomingBlock(i);
315 int pos = PN_father->getBasicBlockIndex(BB);
316 PN->setIncomingValue(i, PN_father->getIncomingValue(pos));
317 }
318 }
319 }
320
321 for (DenseMapIterator begin = phis.begin(),
322 end = phis.end(); begin != end; ++begin) {
323 PHINode *PN = begin->first;
324 BasicBlock *BB = PN->getParent();
325 pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
326 SmallVector Preds(PI, PE);
327 for (unsigned size = Preds.size();
328 PI != PE && PN->getNumIncomingValues() != size; ++PI) {
329 bool found = false;
330 for (unsigned i = 0, pn_end = PN->getNumIncomingValues();
331 i < pn_end; ++i) {
332 if (PN->getIncomingBlock(i) == *PI) {
333 found = true;
334 break;
335 }
336 }
337 if (!found) {
338 PN->addIncoming(UndefValue::get(PN->getType()), *PI);
339 }
340 }
341 }
342 }
343
344 /// Return which variable (position on the vector of variables) this phi
345 /// represents on the phis list.
346 ///
347 Instruction* SSI::getPositionPhi(PHINode *PN) {
348 DenseMap::iterator val = phis.find(PN);
349 if (val == phis.end())
350 return 0;
351 else
352 return val->second;
353 }
354
355 /// Return which variable (position on the vector of variables) this phi
356 /// represents on the sigmas list.
357 ///
358 Instruction* SSI::getPositionSigma(PHINode *PN) {
359 DenseMap::iterator val = sigmas.find(PN);
360 if (val == sigmas.end())
361 return 0;
362 else
363 return val->second;
364 }
365
366 /// Initializes
367 ///
368 void SSI::init(SmallVectorImpl &value) {
369 for (SmallVectorImpl::iterator I = value.begin(),
370 E = value.end(); I != E; ++I) {
371 value_original[*I] = (*I)->getParent();
372 defsites[*I].push_back((*I)->getParent());
373 }
374 }
375
376 /// Clean all used resources in this creation of SSI
377 ///
378 void SSI::clean() {
379 phis.clear();
380 sigmas.clear();
381 phisToFix.clear();
382
383 defsites.clear();
384 value_stack.clear();
385 value_original.clear();
386 }
387
388 /// createSSIPass - The public interface to this file...
389 ///
390 FunctionPass *llvm::createSSIPass() { return new SSI(); }
391
392 char SSI::ID = 0;
393 INITIALIZE_PASS(SSI, "ssi",
394 "Static Single Information Construction", false, false);
395
396 /// SSIEverything - A pass that runs createSSI on every non-void variable,
397 /// intended for debugging.
398 namespace {
399 struct SSIEverything : public FunctionPass {
400 static char ID; // Pass identification, replacement for typeid
401 SSIEverything() : FunctionPass(ID) {}
402
403 bool runOnFunction(Function &F);
404
405 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
406 AU.addRequired();
407 }
408 };
409 }
410
411 bool SSIEverything::runOnFunction(Function &F) {
412 SmallVector Insts;
413 SSI &ssi = getAnalysis();
414
415 if (F.isDeclaration() || F.isIntrinsic()) return false;
416
417 for (Function::iterator B = F.begin(), BE = F.end(); B != BE; ++B)
418 for (BasicBlock::iterator I = B->begin(), E = B->end(); I != E; ++I)
419 if (!I->getType()->isVoidTy())
420 Insts.push_back(I);
421
422 ssi.createSSI(Insts);
423 return true;
424 }
425
426 /// createSSIEverythingPass - The public interface to this file...
427 ///
428 FunctionPass *llvm::createSSIEverythingPass() { return new SSIEverything(); }
429
430 char SSIEverything::ID = 0;
431 INITIALIZE_PASS(SSIEverything, "ssi-everything",
432 "Static Single Information Construction", false, false);
+0
-27
test/Transforms/ABCD/basic.ll less more
None ; RUN: opt < %s -abcd -S | FileCheck %s
1
2 define void @test() {
3 ; CHECK: @test
4 ; CHECK-NOT: br i1 %tmp95
5 ; CHECK: ret void
6 entry:
7 br label %bb19
8
9 bb:
10 br label %bb1
11
12 bb1:
13 %tmp7 = icmp sgt i32 %tmp94, 1
14 br i1 %tmp7, label %bb.i.i, label %return
15
16 bb.i.i:
17 br label %return
18
19 bb19:
20 %tmp94 = ashr i32 undef, 3
21 %tmp95 = icmp sgt i32 %tmp94, 16
22 br i1 %tmp95, label %bb, label %return
23
24 return:
25 ret void
26 }
+0
-3
test/Transforms/ABCD/dg.exp less more
None load_lib llvm.exp
1
2 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
+0
-71
test/Transforms/SSI/2009-07-09-Invoke.ll less more
None ; RUN: opt < %s -ssi-everything -disable-output
1 ; PR4511
2
3 %"struct.std::_Vector_base, std::allocator >,std::allocator, std::allocator > > >" = type { %"struct.std::_Vector_base, std::allocator >,std::allocator, std::allocator > > >::_Vector_impl" }
4 %"struct.std::_Vector_base, std::allocator >,std::allocator, std::allocator > > >::_Vector_impl" = type { %"struct.std::basic_string,std::allocator >"*, %"struct.std::basic_string,std::allocator >"*, %"struct.std::basic_string,std::allocator >"* }
5 %"struct.std::basic_string,std::allocator >" = type { %"struct.std::basic_string,std::allocator >::_Alloc_hider" }
6 %"struct.std::basic_string,std::allocator >::_Alloc_hider" = type { i8* }
7 %"struct.std::basic_string,std::allocator >::_Rep" = type { %"struct.std::basic_string,std::allocator >::_Rep_base" }
8 %"struct.std::basic_string,std::allocator >::_Rep_base" = type { i32, i32, i32 }
9 %"struct.std::vector, std::allocator >,std::allocator, std::allocator > > >" = type { %"struct.std::_Vector_base, std::allocator >,std::allocator, std::allocator > > >" }
10
11 declare void @_Unwind_Resume(i8*)
12
13 declare fastcc %"struct.std::basic_string,std::allocator >"* @_ZSt24__uninitialized_copy_auxIPSsS0_ET0_T_S2_S1_St12__false_type(%"struct.std::basic_string,std::allocator >"*, %"struct.std::basic_string,std::allocator >"*, %"struct.std::basic_string,std::allocator >"*)
14
15 define fastcc void @_ZNSt6vectorISsSaISsEE9push_backERKSs(%"struct.std::vector, std::allocator >,std::allocator, std::allocator > > >"* nocapture %this, %"struct.std::basic_string,std::allocator >"* nocapture %__x) {
16 entry:
17 br i1 undef, label %_ZNSt12_Vector_baseISsSaISsEE11_M_allocateEj.exit.i, label %bb
18
19 bb: ; preds = %entry
20 ret void
21
22 _ZNSt12_Vector_baseISsSaISsEE11_M_allocateEj.exit.i: ; preds = %entry
23 %0 = invoke fastcc %"struct.std::basic_string,std::allocator >"* @_ZSt24__uninitialized_copy_auxIPSsS0_ET0_T_S2_S1_St12__false_type(%"struct.std::basic_string,std::allocator >"* undef, %"struct.std::basic_string,std::allocator >"* undef, %"struct.std::basic_string,std::allocator >"* undef)
24 to label %invcont14.i unwind label %ppad81.i ; <%"struct.std::basic_string,std::allocator >"*> [#uses=3]
25
26 invcont14.i: ; preds = %_ZNSt12_Vector_baseISsSaISsEE11_M_allocateEj.exit.i
27 %1 = icmp eq %"struct.std::basic_string,std::allocator >"* %0, null ; [#uses=1]
28 br i1 %1, label %bb19.i, label %bb.i17.i
29
30 bb.i17.i: ; preds = %invcont14.i
31 %2 = invoke fastcc i8* @_ZNSs4_Rep8_M_cloneERKSaIcEj(%"struct.std::basic_string,std::allocator >::_Rep"* undef, i32 0)
32 to label %bb2.i25.i unwind label %ppad.i.i.i23.i ; [#uses=0]
33
34 ppad.i.i.i23.i: ; preds = %bb.i17.i
35 invoke void @_Unwind_Resume(i8* undef)
36 to label %.noexc.i24.i unwind label %lpad.i29.i
37
38 .noexc.i24.i: ; preds = %ppad.i.i.i23.i
39 unreachable
40
41 bb2.i25.i: ; preds = %bb.i17.i
42 unreachable
43
44 lpad.i29.i: ; preds = %ppad.i.i.i23.i
45 invoke void @_Unwind_Resume(i8* undef)
46 to label %.noexc.i9 unwind label %ppad81.i
47
48 .noexc.i9: ; preds = %lpad.i29.i
49 unreachable
50
51 bb19.i: ; preds = %invcont14.i
52 %3 = getelementptr %"struct.std::basic_string,std::allocator >"* %0, i32 1 ; <%"struct.std::basic_string,std::allocator >"*> [#uses=2]
53 %4 = invoke fastcc %"struct.std::basic_string,std::allocator >"* @_ZSt24__uninitialized_copy_auxIPSsS0_ET0_T_S2_S1_St12__false_type(%"struct.std::basic_string,std::allocator >"* undef, %"struct.std::basic_string,std::allocator >"* undef, %"struct.std::basic_string,std::allocator >"* %3)
54 to label %invcont20.i unwind label %ppad81.i ; <%"struct.std::basic_string,std::allocator >"*> [#uses=0]
55
56 invcont20.i: ; preds = %bb19.i
57 unreachable
58
59 invcont32.i: ; preds = %ppad81.i
60 unreachable
61
62 ppad81.i: ; preds = %bb19.i, %lpad.i29.i, %_ZNSt12_Vector_baseISsSaISsEE11_M_allocateEj.exit.i
63 %__new_finish.0.i = phi %"struct.std::basic_string,std::allocator >"* [ %0, %lpad.i29.i ], [ undef, %_ZNSt12_Vector_baseISsSaISsEE11_M_allocateEj.exit.i ], [ %3, %bb19.i ] ; <%"struct.std::basic_string,std::allocator >"*> [#uses=0]
64 br i1 undef, label %invcont32.i, label %bb.i.i.i.i
65
66 bb.i.i.i.i: ; preds = %bb.i.i.i.i, %ppad81.i
67 br label %bb.i.i.i.i
68 }
69
70 declare fastcc i8* @_ZNSs4_Rep8_M_cloneERKSaIcEj(%"struct.std::basic_string,std::allocator >::_Rep"* nocapture, i32)
+0
-19
test/Transforms/SSI/2009-08-15-UnreachableBB.ll less more
None ; RUN: opt < %s -ssi-everything -disable-output
1
2 declare fastcc i32 @ras_Empty(i8** nocapture) nounwind readonly
3
4 define i32 @cc_Tautology() nounwind {
5 entry:
6 unreachable
7
8 cc_InitData.exit: ; No predecessors!
9 %0 = call fastcc i32 @ras_Empty(i8** undef) nounwind ; [#uses=1]
10 %1 = icmp eq i32 %0, 0 ; [#uses=1]
11 br i1 %1, label %bb2, label %bb6
12
13 bb2: ; preds = %cc_InitData.exit
14 unreachable
15
16 bb6: ; preds = %cc_InitData.exit
17 ret i32 undef
18 }
+0
-15
test/Transforms/SSI/2009-08-17-CritEdge.ll less more
None ; RUN: opt < %s -ssi-everything -disable-output
1
2 define void @test(i32 %x) {
3 entry:
4 br label %label1
5 label1:
6 %A = phi i32 [ 0, %entry ], [ %A.1, %label2 ]
7 %B = icmp slt i32 %A, %x
8 br i1 %B, label %label2, label %label2
9 label2:
10 %A.1 = add i32 %A, 1
11 br label %label1
12 label3: ; No predecessors!
13 ret void
14 }
+0
-22
test/Transforms/SSI/2009-08-19-UnreachableBB2.ll less more
None ; RUN: opt < %s -ssi-everything -disable-output
1
2 define void @foo() {
3 entry:
4 %tmp0 = load i64* undef, align 4 ; [#uses=3]
5 br i1 undef, label %end_stmt_playback, label %bb16
6
7 readJournalHdr.exit: ; No predecessors!
8 br label %end_stmt_playback
9
10 bb16: ; preds = %bb7
11 %tmp1 = icmp slt i64 0, %tmp0 ; [#uses=1]
12 br i1 %tmp1, label %bb16, label %bb17
13
14 bb17: ; preds = %bb16
15 store i64 %tmp0, i64* undef, align 4
16 br label %end_stmt_playback
17
18 end_stmt_playback: ; preds = %bb17, %readJournalHdr.exit, %bb6, %bb2
19 store i64 %tmp0, i64* undef, align 4
20 ret void
21 }
+0
-3
test/Transforms/SSI/dg.exp less more
None load_lib llvm.exp
1
2 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
+0
-22
test/Transforms/SSI/ssiphi.ll less more
None ; RUN: opt < %s -ssi-everything -S | FileCheck %s
1
2 declare void @use(i32)
3 declare i32 @create()
4
5 define i32 @foo() {
6 entry:
7 %x = call i32 @create()
8 %y = icmp slt i32 %x, 10
9 br i1 %y, label %T, label %F
10 T:
11 ; CHECK: SSI_sigma
12 call void @use(i32 %x)
13 br label %join
14 F:
15 ; CHECK: SSI_sigma
16 call void @use(i32 %x)
17 br label %join
18 join:
19 ; CHECK: SSI_phi
20 ret i32 %x
21 }