llvm.org GIT mirror llvm / b198d4e
[ICP] Expose unconditional call promotion interface This patch modifies the indirect call promotion utilities by exposing and using an unconditional call promotion interface. The unconditional promotion interface (i.e., call promotion without creating an if-then-else) can be used if it's known that an indirect call has only one possible callee. The existing conditional promotion interface uses this unconditional interface to promote an indirect call after it has been versioned and placed within the "then" block. A consequence of unconditional promotion is that the fix-up operations for phi nodes in the normal destination of invoke instructions are changed. This is necessary because the existing implementation assumed that an invoke had been versioned, creating a "merge" block where a return value bitcast could be placed. In the new implementation, the edge between a promoted invoke's parent block and its normal destination is split if needed to add a bitcast for the return value. If the invoke is also versioned, the phi node merging the return value of the promoted and original invoke instructions is placed in the "merge" block. Differential Revision: https://reviews.llvm.org/D40751 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321210 91177308-0d34-0410-b5e6-96231b3b80d8 Matthew Simpson 1 year, 9 months ago
8 changed file(s) with 210 addition(s) and 101 deletion(s). Raw diff Collapse all Expand all
2828 bool isLegalToPromote(CallSite CS, Function *Callee,
2929 const char **FailureReason = nullptr);
3030
31 /// Promote the given indirect call site to unconditionally call \p Callee.
32 ///
33 /// This function promotes the given call site, returning the direct call or
34 /// invoke instruction. If the function type of the call site doesn't match that
35 /// of the callee, bitcast instructions are inserted where appropriate. If \p
36 /// RetBitCast is non-null, it will be used to store the return value bitcast,
37 /// if created.
38 Instruction *promoteCall(CallSite CS, Function *Callee,
39 CastInst **RetBitCast = nullptr);
40
3141 /// Promote the given indirect call site to conditionally call \p Callee.
3242 ///
3343 /// This function creates an if-then-else structure at the location of the call
34 /// site. The original call site is promoted and moved into the "then" block. A
35 /// clone of the indirect call site is placed in the "else" block and returned.
36 /// If \p BranchWeights is non-null, it will be used to set !prof metadata on
37 /// the new conditional branch.
44 /// site. The original call site is moved into the "else" block. A clone of the
45 /// indirect call site is promoted, placed in the "then" block, and returned. If
46 /// \p BranchWeights is non-null, it will be used to set !prof metadata on the
47 /// new conditional branch.
3848 Instruction *promoteCallWithIfThenElse(CallSite CS, Function *Callee,
3949 MDNode *BranchWeights = nullptr);
4050
2222 /// Fix-up phi nodes in an invoke instruction's normal destination.
2323 ///
2424 /// After versioning an invoke instruction, values coming from the original
25 /// block will now either be coming from the original block or the "else" block.
25 /// block will now be coming from the "merge" block. For example, in the code
26 /// below:
27 ///
28 /// then_bb:
29 /// %t0 = invoke i32 %ptr() to label %merge_bb unwind label %unwind_dst
30 ///
31 /// else_bb:
32 /// %t1 = invoke i32 %ptr() to label %merge_bb unwind label %unwind_dst
33 ///
34 /// merge_bb:
35 /// %t2 = phi i32 [ %t0, %then_bb ], [ %t1, %else_bb ]
36 /// br %normal_dst
37 ///
38 /// normal_dst:
39 /// %t3 = phi i32 [ %x, %orig_bb ], ...
40 ///
41 /// "orig_bb" is no longer a predecessor of "normal_dst", so the phi nodes in
42 /// "normal_dst" must be fixed to refer to "merge_bb":
43 ///
44 /// normal_dst:
45 /// %t3 = phi i32 [ %x, %merge_bb ], ...
46 ///
2647 static void fixupPHINodeForNormalDest(InvokeInst *Invoke, BasicBlock *OrigBlock,
27 BasicBlock *ElseBlock,
28 Instruction *NewInst) {
48 BasicBlock *MergeBlock) {
2949 for (auto &I : *Invoke->getNormalDest()) {
3050 auto *Phi = dyn_cast(&I);
3151 if (!Phi)
3353 int Idx = Phi->getBasicBlockIndex(OrigBlock);
3454 if (Idx == -1)
3555 continue;
36 Value *V = Phi->getIncomingValue(Idx);
37 if (dyn_cast(V) == Invoke) {
38 Phi->setIncomingBlock(Idx, ElseBlock);
39 Phi->addIncoming(NewInst, OrigBlock);
40 continue;
41 }
42 Phi->addIncoming(V, ElseBlock);
56 Phi->setIncomingBlock(Idx, MergeBlock);
4357 }
4458 }
4559
4761 ///
4862 /// After versioning an invoke instruction, values coming from the original
4963 /// block will now be coming from either the "then" block or the "else" block.
64 /// For example, in the code below:
65 ///
66 /// then_bb:
67 /// %t0 = invoke i32 %ptr() to label %merge_bb unwind label %unwind_dst
68 ///
69 /// else_bb:
70 /// %t1 = invoke i32 %ptr() to label %merge_bb unwind label %unwind_dst
71 ///
72 /// unwind_dst:
73 /// %t3 = phi i32 [ %x, %orig_bb ], ...
74 ///
75 /// "orig_bb" is no longer a predecessor of "unwind_dst", so the phi nodes in
76 /// "unwind_dst" must be fixed to refer to "then_bb" and "else_bb":
77 ///
78 /// unwind_dst:
79 /// %t3 = phi i32 [ %x, %then_bb ], [ %x, %else_bb ], ...
80 ///
5081 static void fixupPHINodeForUnwindDest(InvokeInst *Invoke, BasicBlock *OrigBlock,
5182 BasicBlock *ThenBlock,
5283 BasicBlock *ElseBlock) {
6394 }
6495 }
6596
66 /// Get the phi node having the returned value of a call or invoke instruction
67 /// as it's operand.
68 static bool getRetPhiNode(Instruction *Inst, BasicBlock *Block) {
69 BasicBlock *FromBlock = Inst->getParent();
70 for (auto &I : *Block) {
71 PHINode *PHI = dyn_cast(&I);
72 if (!PHI)
73 break;
74 int Idx = PHI->getBasicBlockIndex(FromBlock);
75 if (Idx == -1)
76 continue;
77 auto *V = PHI->getIncomingValue(Idx);
78 if (V == Inst)
79 return true;
80 }
81 return false;
82 }
83
8497 /// Create a phi node for the returned value of a call or invoke instruction.
8598 ///
8699 /// After versioning a call or invoke instruction that returns a value, we have
87100 /// to merge the value of the original and new instructions. We do this by
88101 /// creating a phi node and replacing uses of the original instruction with this
89102 /// phi node.
90 static void createRetPHINode(Instruction *OrigInst, Instruction *NewInst) {
103 ///
104 /// For example, if \p OrigInst is defined in "else_bb" and \p NewInst is
105 /// defined in "then_bb", we create the following phi node:
106 ///
107 /// ; Uses of the original instruction are replaced by uses of the phi node.
108 /// %t0 = phi i32 [ %orig_inst, %else_bb ], [ %new_inst, %then_bb ],
109 ///
110 static void createRetPHINode(Instruction *OrigInst, Instruction *NewInst,
111 BasicBlock *MergeBlock, IRBuilder<> &Builder) {
91112
92113 if (OrigInst->getType()->isVoidTy() || OrigInst->use_empty())
93114 return;
94115
95 BasicBlock *RetValBB = NewInst->getParent();
96 if (auto *Invoke = dyn_cast(NewInst))
97 RetValBB = Invoke->getNormalDest();
98 BasicBlock *PhiBB = RetValBB->getSingleSuccessor();
99
100 if (getRetPhiNode(OrigInst, PhiBB))
101 return;
102
103 IRBuilder<> Builder(&PhiBB->front());
116 Builder.SetInsertPoint(&MergeBlock->front());
104117 PHINode *Phi = Builder.CreatePHI(OrigInst->getType(), 0);
105118 SmallVector UsersToUpdate;
106119 for (User *U : OrigInst->users())
108121 for (User *U : UsersToUpdate)
109122 U->replaceUsesOfWith(OrigInst, Phi);
110123 Phi->addIncoming(OrigInst, OrigInst->getParent());
111 Phi->addIncoming(NewInst, RetValBB);
124 Phi->addIncoming(NewInst, NewInst->getParent());
112125 }
113126
114127 /// Cast a call or invoke instruction to the given type.
117130 /// that of the callee. If this is the case, we have to cast the returned value
118131 /// to the correct type. The location of the cast depends on if we have a call
119132 /// or invoke instruction.
120 Instruction *createRetBitCast(CallSite CS, Type *RetTy) {
133 ///
134 /// For example, if the call instruction below requires a bitcast after
135 /// promotion:
136 ///
137 /// orig_bb:
138 /// %t0 = call i32 @func()
139 /// ...
140 ///
141 /// The bitcast is placed after the call instruction:
142 ///
143 /// orig_bb:
144 /// ; Uses of the original return value are replaced by uses of the bitcast.
145 /// %t0 = call i32 @func()
146 /// %t1 = bitcast i32 %t0 to ...
147 /// ...
148 ///
149 /// A similar transformation is performed for invoke instructions. However,
150 /// since invokes are terminating, a new block is created for the bitcast. For
151 /// example, if the invoke instruction below requires a bitcast after promotion:
152 ///
153 /// orig_bb:
154 /// %t0 = invoke i32 @func() to label %normal_dst unwind label %unwind_dst
155 ///
156 /// The edge between the original block and the invoke's normal destination is
157 /// split, and the bitcast is placed there:
158 ///
159 /// orig_bb:
160 /// %t0 = invoke i32 @func() to label %split_bb unwind label %unwind_dst
161 ///
162 /// split_bb:
163 /// ; Uses of the original return value are replaced by uses of the bitcast.
164 /// %t1 = bitcast i32 %t0 to ...
165 /// br label %normal_dst
166 ///
167 static void createRetBitCast(CallSite CS, Type *RetTy, CastInst **RetBitCast) {
121168
122169 // Save the users of the calling instruction. These uses will be changed to
123170 // use the bitcast after we create it.
129176 // value. The location depends on if we have a call or invoke instruction.
130177 Instruction *InsertBefore = nullptr;
131178 if (auto *Invoke = dyn_cast(CS.getInstruction()))
132 InsertBefore = &*Invoke->getNormalDest()->getFirstInsertionPt();
179 InsertBefore =
180 &SplitEdge(Invoke->getParent(), Invoke->getNormalDest())->front();
133181 else
134182 InsertBefore = &*std::next(CS.getInstruction()->getIterator());
135183
136184 // Bitcast the return value to the correct type.
137185 auto *Cast = CastInst::Create(Instruction::BitCast, CS.getInstruction(),
138186 RetTy, "", InsertBefore);
187 if (RetBitCast)
188 *RetBitCast = Cast;
139189
140190 // Replace all the original uses of the calling instruction with the bitcast.
141191 for (User *U : UsersToUpdate)
142192 U->replaceUsesOfWith(CS.getInstruction(), Cast);
143
144 return Cast;
145193 }
146194
147195 /// Predicate and clone the given call site.
151199 /// callee. The original call site is moved into the "else" block, and a clone
152200 /// of the call site is placed in the "then" block. The cloned instruction is
153201 /// returned.
202 ///
203 /// For example, the call instruction below:
204 ///
205 /// orig_bb:
206 /// %t0 = call i32 %ptr()
207 /// ...
208 ///
209 /// Is replace by the following:
210 ///
211 /// orig_bb:
212 /// %cond = icmp eq i32 ()* %ptr, @func
213 /// br i1 %cond, %then_bb, %else_bb
214 ///
215 /// then_bb:
216 /// ; The clone of the original call instruction is placed in the "then"
217 /// ; block. It is not yet promoted.
218 /// %t1 = call i32 %ptr()
219 /// br merge_bb
220 ///
221 /// else_bb:
222 /// ; The original call instruction is moved to the "else" block.
223 /// %t0 = call i32 %ptr()
224 /// br merge_bb
225 ///
226 /// merge_bb:
227 /// ; Uses of the original call instruction are replaced by uses of the phi
228 /// ; node.
229 /// %t2 = phi i32 [ %t0, %else_bb ], [ %t1, %then_bb ]
230 /// ...
231 ///
232 /// A similar transformation is performed for invoke instructions. However,
233 /// since invokes are terminating, more work is required. For example, the
234 /// invoke instruction below:
235 ///
236 /// orig_bb:
237 /// %t0 = invoke %ptr() to label %normal_dst unwind label %unwind_dst
238 ///
239 /// Is replace by the following:
240 ///
241 /// orig_bb:
242 /// %cond = icmp eq i32 ()* %ptr, @func
243 /// br i1 %cond, %then_bb, %else_bb
244 ///
245 /// then_bb:
246 /// ; The clone of the original invoke instruction is placed in the "then"
247 /// ; block, and its normal destination is set to the "merge" block. It is
248 /// ; not yet promoted.
249 /// %t1 = invoke i32 %ptr() to label %merge_bb unwind label %unwind_dst
250 ///
251 /// else_bb:
252 /// ; The original invoke instruction is moved into the "else" block, and
253 /// ; its normal destination is set to the "merge" block.
254 /// %t0 = invoke i32 %ptr() to label %merge_bb unwind label %unwind_dst
255 ///
256 /// merge_bb:
257 /// ; Uses of the original invoke instruction are replaced by uses of the
258 /// ; phi node, and the merge block branches to the normal destination.
259 /// %t2 = phi i32 [ %t0, %else_bb ], [ %t1, %then_bb ]
260 /// br %normal_dst
261 ///
154262 static Instruction *versionCallSite(CallSite CS, Value *Callee,
155 MDNode *BranchWeights,
156 BasicBlock *&ThenBlock,
157 BasicBlock *&ElseBlock,
158 BasicBlock *&MergeBlock) {
263 MDNode *BranchWeights) {
159264
160265 IRBuilder<> Builder(CS.getInstruction());
161266 Instruction *OrigInst = CS.getInstruction();
267 BasicBlock *OrigBlock = OrigInst->getParent();
162268
163269 // Create the compare. The called value and callee must have the same type to
164270 // be compared.
165 auto *LHS =
166 Builder.CreateBitCast(CS.getCalledValue(), Builder.getInt8PtrTy());
167 auto *RHS = Builder.CreateBitCast(Callee, Builder.getInt8PtrTy());
168 auto *Cond = Builder.CreateICmpEQ(LHS, RHS);
271 if (CS.getCalledValue()->getType() != Callee->getType())
272 Callee = Builder.CreateBitCast(Callee, CS.getCalledValue()->getType());
273 auto *Cond = Builder.CreateICmpEQ(CS.getCalledValue(), Callee);
169274
170275 // Create an if-then-else structure. The original instruction is moved into
171276 // the "else" block, and a clone of the original instruction is placed in the
174279 TerminatorInst *ElseTerm = nullptr;
175280 SplitBlockAndInsertIfThenElse(Cond, CS.getInstruction(), &ThenTerm, &ElseTerm,
176281 BranchWeights);
177 ThenBlock = ThenTerm->getParent();
178 ElseBlock = ElseTerm->getParent();
179 MergeBlock = OrigInst->getParent();
282 BasicBlock *ThenBlock = ThenTerm->getParent();
283 BasicBlock *ElseBlock = ElseTerm->getParent();
284 BasicBlock *MergeBlock = OrigInst->getParent();
180285
181286 ThenBlock->setName("if.true.direct_targ");
182287 ElseBlock->setName("if.false.orig_indirect");
187292 NewInst->insertBefore(ThenTerm);
188293
189294 // If the original call site is an invoke instruction, we have extra work to
190 // do since invoke instructions are terminating.
295 // do since invoke instructions are terminating. We have to fix-up phi nodes
296 // in the invoke's normal and unwind destinations.
191297 if (auto *OrigInvoke = dyn_cast(OrigInst)) {
192298 auto *NewInvoke = cast(NewInst);
193299
200306 Builder.SetInsertPoint(MergeBlock);
201307 Builder.CreateBr(OrigInvoke->getNormalDest());
202308
203 // Now set the normal destination of new the invoke instruction to be the
309 // Fix-up phi nodes in the original invoke's normal and unwind destinations.
310 fixupPHINodeForNormalDest(OrigInvoke, OrigBlock, MergeBlock);
311 fixupPHINodeForUnwindDest(OrigInvoke, MergeBlock, ThenBlock, ElseBlock);
312
313 // Now set the normal destinations of the invoke instructions to be the
204314 // "merge" block.
315 OrigInvoke->setNormalDest(MergeBlock);
205316 NewInvoke->setNormalDest(MergeBlock);
206317 }
318
319 // Create a phi node for the returned value of the call site.
320 createRetPHINode(OrigInst, NewInst, MergeBlock, Builder);
207321
208322 return NewInst;
209323 }
252366 return true;
253367 }
254368
255 static void promoteCall(CallSite CS, Function *Callee, Instruction *&Cast) {
369 Instruction *llvm::promoteCall(CallSite CS, Function *Callee,
370 CastInst **RetBitCast) {
256371 assert(!CS.getCalledFunction() && "Only indirect call sites can be promoted");
257372
258373 // Set the called function of the call site to be the given callee.
267382 // If the function type of the call site matches that of the callee, no
268383 // additional work is required.
269384 if (CS.getFunctionType() == Callee->getFunctionType())
270 return;
385 return CS.getInstruction();
271386
272387 // Save the return types of the call site and callee.
273388 Type *CallSiteRetTy = CS.getInstruction()->getType();
293408 // If the return type of the call site doesn't match that of the callee, cast
294409 // the returned value to the appropriate type.
295410 if (!CallSiteRetTy->isVoidTy() && CallSiteRetTy != CalleeRetTy)
296 Cast = createRetBitCast(CS, CallSiteRetTy);
411 createRetBitCast(CS, CallSiteRetTy, RetBitCast);
412
413 return CS.getInstruction();
297414 }
298415
299416 Instruction *llvm::promoteCallWithIfThenElse(CallSite CS, Function *Callee,
302419 // Version the indirect call site. If the called value is equal to the given
303420 // callee, 'NewInst' will be executed, otherwise the original call site will
304421 // be executed.
305 BasicBlock *ThenBlock, *ElseBlock, *MergeBlock;
306 Instruction *NewInst = versionCallSite(CS, Callee, BranchWeights, ThenBlock,
307 ElseBlock, MergeBlock);
422 Instruction *NewInst = versionCallSite(CS, Callee, BranchWeights);
308423
309424 // Promote 'NewInst' so that it directly calls the desired function.
310 Instruction *Cast = NewInst;
311 promoteCall(CallSite(NewInst), Callee, Cast);
312
313 // If the original call site is an invoke instruction, we have to fix-up phi
314 // nodes in the invoke's normal and unwind destinations.
315 if (auto *OrigInvoke = dyn_cast(CS.getInstruction())) {
316 fixupPHINodeForNormalDest(OrigInvoke, MergeBlock, ElseBlock, Cast);
317 fixupPHINodeForUnwindDest(OrigInvoke, MergeBlock, ThenBlock, ElseBlock);
318 }
319
320 // Create a phi node for the returned value of the call site.
321 createRetPHINode(CS.getInstruction(), Cast ? Cast : NewInst);
322
323 // Return the new direct call.
324 return NewInst;
425 return promoteCall(CallSite(NewInst), Callee);
325426 }
326427
327428 #undef DEBUG_TYPE
2121 %vtable = load %struct.Base* (%struct.B*)**, %struct.Base* (%struct.B*)*** %tmp2, align 8
2222 %vfn = getelementptr inbounds %struct.Base* (%struct.B*)*, %struct.Base* (%struct.B*)** %vtable, i64 0
2323 %tmp3 = load %struct.Base* (%struct.B*)*, %struct.Base* (%struct.B*)** %vfn, align 8
24 ; ICALL-PROM: [[BITCAST:%[0-9]+]] = bitcast %struct.Base* (%struct.B*)* %tmp3 to i8*
25 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq i8* [[BITCAST]], bitcast (%struct.Derived* (%struct.D*)* @_ZN1D4funcEv to i8*)
24 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq %struct.Base* (%struct.B*)* %tmp3, bitcast (%struct.Derived* (%struct.D*)* @_ZN1D4funcEv to %struct.Base* (%struct.B*)*)
2625 ; ICALL-PROM: br i1 [[CMP]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
2726 ; ICALL-PROM:if.true.direct_targ:
2827 ; ICALL-PROM: [[ARG_BITCAST:%[0-9]+]] = bitcast %struct.B* %tmp1 to %struct.D*
3131 %vtable = load %struct.Base* (%struct.B*)**, %struct.Base* (%struct.B*)*** %tmp2, align 8
3232 %vfn = getelementptr inbounds %struct.Base* (%struct.B*)*, %struct.Base* (%struct.B*)** %vtable, i64 0
3333 %tmp3 = load %struct.Base* (%struct.B*)*, %struct.Base* (%struct.B*)** %vfn, align 8
34 ; ICALL-PROM: [[BITCAST:%[0-9]+]] = bitcast %struct.Base* (%struct.B*)* %tmp3 to i8*
35 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq i8* [[BITCAST]], bitcast (%struct.Derived* (%struct.D*)* @_ZN1D4funcEv to i8*)
34 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq %struct.Base* (%struct.B*)* %tmp3, bitcast (%struct.Derived* (%struct.D*)* @_ZN1D4funcEv to %struct.Base* (%struct.B*)*)
3635 ; ICALL-PROM: br i1 [[CMP]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
3736 ; ICALL-PROM:if.true.direct_targ:
3837 ; ICALL-PROM: [[ARG_BITCAST:%[0-9]+]] = bitcast %struct.B* %tmp1 to %struct.D*
3938 ; ICALL-PROM: [[DIRCALL_RET:%[0-9]+]] = invoke %struct.Derived* @_ZN1D4funcEv(%struct.D* [[ARG_BITCAST]])
40 ; ICALL-PROM: to label %if.end.icp unwind label %lpad
39 ; ICALL-PROM: to label %if.true.direct_targ.if.end.icp_crit_edge unwind label %lpad
40 ; ICALL-PROM:if.true.direct_targ.if.end.icp_crit_edge:
41 ; ICALL-PROM: [[DIRCALL_RET_CAST:%[0-9]+]] = bitcast %struct.Derived* [[DIRCALL_RET]] to %struct.Base*
42 ; ICALL-PROM: br label %if.end.icp
4143 ; ICALL-PROM:if.false.orig_indirect:
4244 ; ICAll-PROM: %call2 = invoke %struct.Base* %tmp3(%struct.B* %tmp1)
4345 ; ICAll-PROM: to label %invoke.cont1 unwind label %lpad
4446 ; ICALL-PROM:if.end.icp:
45 ; ICALL-PROM: [[DIRCALL_RET_CAST:%[0-9]+]] = bitcast %struct.Derived* [[DIRCALL_RET]] to %struct.Base*
4647 ; ICALL-PROM: br label %invoke.cont1
4748 %call2 = invoke %struct.Base* %tmp3(%struct.B* %tmp1)
4849 to label %invoke.cont1 unwind label %lpad, !prof !1
1919 define i32 @_Z3goov() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
2020 entry:
2121 %tmp = load void ()*, void ()** @foo1, align 8
22 ; ICP: [[BITCAST_IC1:%[0-9]+]] = bitcast void ()* %tmp to i8*
23 ; ICP: [[CMP_IC1:%[0-9]+]] = icmp eq i8* [[BITCAST_IC1]], bitcast (void ()* @_ZL4bar1v to i8*)
22 ; ICP: [[CMP_IC1:%[0-9]+]] = icmp eq void ()* %tmp, @_ZL4bar1v
2423 ; ICP: br i1 [[CMP_IC1]], label %[[TRUE_LABEL_IC1:.*]], label %[[FALSE_LABEL_IC1:.*]], !prof [[BRANCH_WEIGHT:![0-9]+]]
2524 ; ICP:[[TRUE_LABEL_IC1]]:
2625 ; ICP: invoke void @_ZL4bar1v()
4847
4948 try.cont:
5049 %tmp6 = load i32 ()*, i32 ()** @foo2, align 8
51 ; ICP: [[BITCAST_IC2:%[0-9]+]] = bitcast i32 ()* %tmp6 to i8*
52 ; ICP: [[CMP_IC2:%[0-9]+]] = icmp eq i8* [[BITCAST_IC2]], bitcast (i32 ()* @_ZL4bar2v to i8*)
50 ; ICP: [[CMP_IC2:%[0-9]+]] = icmp eq i32 ()* %tmp6, @_ZL4bar2v
5351 ; ICP: br i1 [[CMP_IC2]], label %[[TRUE_LABEL_IC2:.*]], label %[[FALSE_LABEL_IC2:.*]], !prof [[BRANCH_WEIGHT:![0-9]+]]
5452 ; ICP:[[TRUE_LABEL_IC2]]:
55 ; ICP: [[RESULT_IC2:%[0-9]+]] = invoke i32 @_ZL4bar2v()
56 ; ICP: to label %[[DCALL_NORMAL_DEST_IC2:.*]] unwind label %lpad1
53 ; ICP: [[RESULT_IC2_0:%[0-9]+]] = invoke i32 @_ZL4bar2v()
54 ; ICP: to label %[[MERGE_BB:.*]] unwind label %lpad1
5755 ; ICP:[[FALSE_LABEL_IC2]]:
56 ; ICP: [[RESULT_IC2_1:%.+]] = invoke i32 %tmp6()
57 ; ICP: to label %[[MERGE_BB]] unwind label %lpad1
5858 %call = invoke i32 %tmp6()
5959 to label %try.cont8 unwind label %lpad1, !prof !3
6060
61 ; ICP:[[DCALL_NORMAL_DEST_IC2]]:
61 ; ICP:[[MERGE_BB]]:
62 ; ICP: [[MERGE_PHI:%.+]] = phi i32 [ [[RESULT_IC2_1]], %[[FALSE_LABEL_IC2]] ], [ [[RESULT_IC2_0]], %[[TRUE_LABEL_IC2]] ]
6263 ; ICP: br label %try.cont8
6364 lpad1:
6465 %tmp7 = landingpad { i8*, i32 }
7677
7778 try.cont8:
7879 %i.0 = phi i32 [ undef, %catch6 ], [ %call, %try.cont ]
79 ; ICP: %i.0 = phi i32 [ undef, %catch6 ], [ %call, %[[FALSE_LABEL_IC2]] ], [ [[RESULT_IC2]], %[[DCALL_NORMAL_DEST_IC2]] ]
80 ; ICP: %i.0 = phi i32 [ undef, %catch6 ], [ [[MERGE_PHI]], %[[MERGE_BB]] ]
8081 ret i32 %i.0
8182
8283 eh.resume:
1717
1818 if.end: ; preds = %entry
1919 %fptr = load i32 ()*, i32 ()** @pfptr, align 8
20 ; ICP: [[BITCAST_IC1:%[0-9]+]] = bitcast i32 ()* %fptr to i8*
21 ; ICP: [[CMP_IC1:%[0-9]+]] = icmp eq i8* [[BITCAST_IC1]], bitcast (i32 ()* @_ZL4bar1v to i8*)
20 ; ICP: [[CMP_IC1:%[0-9]+]] = icmp eq i32 ()* %fptr, @_ZL4bar1v
2221 ; ICP: br i1 [[CMP_IC1]], label %[[TRUE_LABEL_IC1:.*]], label %[[FALSE_LABEL_IC1:.*]], !prof [[BRANCH_WEIGHT:![0-9]+]]
2322 ; ICP:[[TRUE_LABEL_IC1]]:
2423 ; ICP: invoke i32 @_ZL4bar1v()
1212 define i32 @bar() #1 {
1313 entry:
1414 %tmp = load i32 (i32, ...)*, i32 (i32, ...)** @foo, align 8
15 ; ICALL-PROM: [[BITCAST:%[0-9]+]] = bitcast i32 (i32, ...)* %tmp to i8*
16 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq i8* [[BITCAST]], bitcast (i32 (i32, ...)* @va_func to i8*)
15 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq i32 (i32, ...)* %tmp, @va_func
1716 ; ICALL-PROM: br i1 [[CMP]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
1817 ; ICALL-PROM:if.true.direct_targ:
1918 ; ICALL-PROM: [[DIRCALL_RET:%[0-9]+]] = call i32 (i32, ...) @va_func(i32 3, i32 12, i32 22, i32 4)
4242 define i32 @bar() {
4343 entry:
4444 %tmp = load i32 ()*, i32 ()** @foo, align 8
45 ; ICALL-PROM: [[BITCAST:%[0-9]+]] = bitcast i32 ()* %tmp to i8*
46 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq i8* [[BITCAST]], bitcast (i32 ()* @func4 to i8*)
45 ; ICALL-PROM: [[CMP:%[0-9]+]] = icmp eq i32 ()* %tmp, @func4
4746 ; ICALL-PROM: br i1 [[CMP]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
4847 ; ICALL-PROM: if.true.direct_targ:
4948 ; ICALL-PROM: [[DIRCALL_RET:%[0-9]+]] = call i32 @func4()