llvm.org GIT mirror llvm / 18d1471
Revert r323738; that was not the one I wanted to merge git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@323739 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 1 year, 7 months ago
2 changed file(s) with 4 addition(s) and 89 deletion(s). Raw diff Collapse all Expand all
1313 #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
1414 #include "llvm/ADT/DepthFirstIterator.h"
1515 #include "llvm/ADT/Optional.h"
16 #include "llvm/ADT/PostOrderIterator.h"
1716 #include "llvm/ADT/SmallVector.h"
1817 #include "llvm/ADT/Statistic.h"
1918 #include "llvm/Analysis/GlobalsModRef.h"
120119 return true;
121120 }
122121
123 static bool processPHI(PHINode *P, LazyValueInfo *LVI, const SimplifyQuery &SQ,
124 DenseSet &ReachableBlocks) {
122 static bool processPHI(PHINode *P, LazyValueInfo *LVI,
123 const SimplifyQuery &SQ) {
125124 bool Changed = false;
126125
127126 BasicBlock *BB = P->getParent();
129128 Value *Incoming = P->getIncomingValue(i);
130129 if (isa(Incoming)) continue;
131130
132 // If the incoming value is coming from an unreachable block, replace
133 // it with undef and go on. This is good for two reasons:
134 // 1) We skip an LVI query for an unreachable block
135 // 2) We transform the incoming value so that the code below doesn't
136 // mess around with IR in unreachable blocks.
137 BasicBlock *IncomingBB = P->getIncomingBlock(i);
138 if (!ReachableBlocks.count(IncomingBB)) {
139 P->setIncomingValue(i, UndefValue::get(P->getType()));
140 continue;
141 }
142
143 Value *V = LVI->getConstantOnEdge(Incoming, IncomingBB, BB, P);
131 Value *V = LVI->getConstantOnEdge(Incoming, P->getIncomingBlock(i), BB, P);
144132
145133 // Look if the incoming value is a select with a scalar condition for which
146134 // LVI can tells us the value. In that case replace the incoming value with
572560
573561 static bool runImpl(Function &F, LazyValueInfo *LVI, const SimplifyQuery &SQ) {
574562 bool FnChanged = false;
575
576 // Compute reachability from the entry block of this function via an RPO
577 // walk. We use this information when processing PHIs.
578 DenseSet ReachableBlocks;
579 ReversePostOrderTraversal RPOT(&F);
580 for (BasicBlock *BB : RPOT)
581 ReachableBlocks.insert(BB);
582
583563 // Visiting in a pre-order depth-first traversal causes us to simplify early
584564 // blocks before querying later blocks (which require us to analyze early
585565 // blocks). Eagerly simplifying shallow blocks means there is strictly less
594574 BBChanged |= processSelect(cast(II), LVI);
595575 break;
596576 case Instruction::PHI:
597 BBChanged |= processPHI(cast(II), LVI, SQ, ReachableBlocks);
577 BBChanged |= processPHI(cast(II), LVI, SQ);
598578 break;
599579 case Instruction::ICmp:
600580 case Instruction::FCmp:
+0
-65
test/Transforms/CorrelatedValuePropagation/pr35807.ll less more
None ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -correlated-propagation -S %s | FileCheck %s
2
3 target triple = "x86_64-apple-darwin17.4.0"
4
5 define void @patatino() {
6 ; CHECK-LABEL: @patatino(
7 ; CHECK-NEXT: br i1 undef, label [[BB3:%.*]], label [[BB4:%.*]]
8 ; CHECK: bb3:
9 ; CHECK-NEXT: br label [[BB3]]
10 ; CHECK: bb4:
11 ; CHECK-NEXT: br i1 undef, label [[BB40:%.*]], label [[BB22:%.*]]
12 ; CHECK: bb7:
13 ; CHECK-NEXT: br label [[BB14:%.*]]
14 ; CHECK: bb12:
15 ; CHECK-NEXT: br label [[BB14]]
16 ; CHECK: bb14:
17 ; CHECK-NEXT: [[TMP19:%.*]] = icmp sgt i32 undef, undef
18 ; CHECK-NEXT: [[TMP20:%.*]] = select i1 [[TMP19]], i64 [[TMP20]], i64 0
19 ; CHECK-NEXT: br i1 undef, label [[BB40]], label [[BB7:%.*]]
20 ; CHECK: bb22:
21 ; CHECK-NEXT: br label [[BB24:%.*]]
22 ; CHECK: bb24:
23 ; CHECK-NEXT: br label [[BB32:%.*]]
24 ; CHECK: bb32:
25 ; CHECK-NEXT: br i1 undef, label [[BB40]], label [[BB24]]
26 ; CHECK: bb40:
27 ; CHECK-NEXT: ret void
28 ;
29 br i1 undef, label %bb3, label %bb4
30
31 bb3:
32 br label %bb3
33
34 bb4:
35 br i1 undef, label %bb40, label %bb22
36
37 bb7:
38 br label %bb14
39
40 bb12:
41 br label %bb14
42
43 ; This block is unreachable. Due to the non-standard definition of
44 ; dominance in LLVM where uses in unreachable blocks are dominated
45 ; by anything, it contains an instruction of the form
46 ; %def = OP %def, %something
47 bb14:
48 %tmp19 = icmp sgt i32 undef, undef
49 %tmp20 = select i1 %tmp19, i64 %tmp20, i64 0
50 br i1 undef, label %bb40, label %bb7
51
52 bb22:
53 br label %bb24
54
55 bb24:
56 br label %bb32
57
58 bb32:
59 br i1 undef, label %bb40, label %bb24
60
61 bb40:
62 %tmp41 = phi i64 [ 4, %bb4 ], [ %tmp20, %bb14 ], [ undef, %bb32 ]
63 ret void
64 }