llvm.org GIT mirror llvm / 32d9701
Ignore dbg intrinsics while propagating conditional expression info. Take 2. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63898 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 10 years ago
2 changed file(s) with 62 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1616 #include "llvm/Constants.h"
1717 #include "llvm/Function.h"
1818 #include "llvm/Instructions.h"
19 #include "llvm/IntrinsicInst.h"
1920 #include "llvm/Pass.h"
2021 #include "llvm/Type.h"
2122 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
133134 // jump directly to the destination instead of going through this block.
134135 void CondProp::SimplifyPredecessors(BranchInst *BI) {
135136 // TODO: We currently only handle the most trival case, where the PHI node has
136 // one use (the branch), and is the only instruction besides the branch in the
137 // block.
137 // one use (the branch), and is the only instruction besides the branch and dbg
138 // intrinsics in the block.
138139 PHINode *PN = cast(BI->getCondition());
139140
140141 if (PN->getNumIncomingValues() == 1) {
147148 if (!PN->hasOneUse()) return;
148149
149150 BasicBlock *BB = BI->getParent();
150 if (&*BB->begin() != PN || &*next(BB->begin()) != BI)
151 if (&*BB->begin() != PN)
152 return;
153 BasicBlock::iterator BBI = BB->begin();
154 BasicBlock::iterator BBE = BB->end();
155 while (BBI != BBE && isa(++BBI));
156 if (&*BBI != BI)
151157 return;
152158
153159 // Ok, we have this really simple case, walk the PHI operands, looking for
175181 // the destination instead of going through this block.
176182 void CondProp::SimplifyPredecessors(SwitchInst *SI) {
177183 // TODO: We currently only handle the most trival case, where the PHI node has
178 // one use (the branch), and is the only instruction besides the branch in the
179 // block.
184 // one use (the branch), and is the only instruction besides the branch and
185 // dbg intrinsics in the block.
180186 PHINode *PN = cast(SI->getCondition());
181187 if (!PN->hasOneUse()) return;
182188
183189 BasicBlock *BB = SI->getParent();
184 if (&*BB->begin() != PN || &*next(BB->begin()) != SI)
190 if (&*BB->begin() != PN)
191 return;
192 BasicBlock::iterator BBI = BB->begin();
193 BasicBlock::iterator BBE = BB->end();
194 while (BBI != BBE && isa(++BBI));
195 if (&*BBI != SI)
185196 return;
186197
187198 bool RemovedPreds = false;
0 ; RUN: llvm-as < %s | opt -condprop | llvm-dis | \
1 ; RUN: not grep {br label}
2
3 %llvm.dbg.anchor.type = type { i32, i32 }
4 %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
5
6 @llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata" ;
7
8 @.str = internal constant [4 x i8] c"a.c\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
9 @.str1 = internal constant [6 x i8] c"/tmp/\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
10 @.str2 = internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*> [#uses=1]
11 @llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([6 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
12
13 declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
14
15
16 define i32 @test(i1 %C) {
17 br i1 %C, label %T1, label %F1
18
19 T1: ; preds = %0
20 call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
21 br label %Cont
22
23 F1: ; preds = %0
24 call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
25 br label %Cont
26
27 Cont: ; preds = %F1, %T1
28 %C2 = phi i1 [ false, %F1 ], [ true, %T1 ] ; [#uses=1]
29 call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
30 br i1 %C2, label %T2, label %F2
31
32 T2: ; preds = %Cont
33 call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
34 call void @bar( )
35 call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
36 ret i32 17
37
38 F2: ; preds = %Cont
39 call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
40 ret i32 1
41 }
42
43 declare void @bar()
44