llvm.org GIT mirror llvm / c39972a
Merging r277691, r277693, and r277773: ------------------------------------------------------------------------ r277691 | majnemer | 2016-08-03 21:24:02 -0700 (Wed, 03 Aug 2016) | 4 lines Reinstate "[CloneFunction] Don't remove side effecting calls" This reinstates r277611 + r277614 and reverts r277642. A cast_or_null should have been a dyn_cast_or_null. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r277693 | majnemer | 2016-08-03 21:47:18 -0700 (Wed, 03 Aug 2016) | 1 line Forgot the dyn_cast_or_null intended for r277691. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r277773 | majnemer | 2016-08-04 14:28:59 -0700 (Thu, 04 Aug 2016) | 6 lines [CloneFunction] Add a testcase for r277691/r277693 PR28848 had a very nice reduction of the underlying cause of the bug. Our ValueMap had, in an entry for an Instruction, a ConstantInt. This is not at all unexpected but should be handled properly. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@277781 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
3 changed file(s) with 80 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
42764276
42774277 // Gracefully handle edge cases where the instruction is not wired into any
42784278 // parent block.
4279 if (I->getParent())
4279 if (I->getParent() && !I->isEHPad() && !isa(I) &&
4280 !I->mayHaveSideEffects())
42804281 I->eraseFromParent();
42814282 } else {
42824283 Worklist.insert(I);
43044305
43054306 // Gracefully handle edge cases where the instruction is not wired into any
43064307 // parent block.
4307 if (I->getParent())
4308 if (I->getParent() && !I->isEHPad() && !isa(I) &&
4309 !I->mayHaveSideEffects())
43084310 I->eraseFromParent();
43094311 }
43104312 return Simplified;
1313 //===----------------------------------------------------------------------===//
1414
1515 #include "llvm/Transforms/Utils/Cloning.h"
16 #include "llvm/ADT/SetVector.h"
1617 #include "llvm/ADT/SmallVector.h"
1718 #include "llvm/Analysis/ConstantFolding.h"
1819 #include "llvm/Analysis/InstructionSimplify.h"
551552 // two PHINodes, the iteration over the old PHIs remains valid, and the
552553 // mapping will just map us to the new node (which may not even be a PHI
553554 // node).
555 const DataLayout &DL = NewFunc->getParent()->getDataLayout();
556 SmallSetVector Worklist;
554557 for (unsigned Idx = 0, Size = PHIToResolve.size(); Idx != Size; ++Idx)
555 if (PHINode *PN = dyn_cast(VMap[PHIToResolve[Idx]]))
556 recursivelySimplifyInstruction(PN);
558 if (isa(VMap[PHIToResolve[Idx]]))
559 Worklist.insert(PHIToResolve[Idx]);
560
561 // Note that we must test the size on each iteration, the worklist can grow.
562 for (unsigned Idx = 0; Idx != Worklist.size(); ++Idx) {
563 const Value *OrigV = Worklist[Idx];
564 auto *I = dyn_cast_or_null(VMap.lookup(OrigV));
565 if (!I)
566 continue;
567
568 // See if this instruction simplifies.
569 Value *SimpleV = SimplifyInstruction(I, DL);
570 if (!SimpleV)
571 continue;
572
573 // Stash away all the uses of the old instruction so we can check them for
574 // recursive simplifications after a RAUW. This is cheaper than checking all
575 // uses of To on the recursive step in most cases.
576 for (const User *U : OrigV->users())
577 Worklist.insert(cast(U));
578
579 // Replace the instruction with its simplified value.
580 I->replaceAllUsesWith(SimpleV);
581
582 // If the original instruction had no side effects, remove it.
583 if (isInstructionTriviallyDead(I))
584 I->eraseFromParent();
585 else
586 VMap[OrigV] = I;
587 }
557588
558589 // Now that the inlined function body has been fully constructed, go through
559590 // and zap unconditional fall-through branches. This happens all the time when
278278 %retval.0 = phi i32* [ %b, %if.end3 ], [ %a, %if.then ]
279279 ret i32* %retval.0
280280 }
281
282 declare i32 @PR28802.external(i32 returned %p1)
283
284 define internal i32 @PR28802.callee() {
285 entry:
286 br label %cont
287
288 cont:
289 %0 = phi i32 [ 0, %entry ]
290 %call = call i32 @PR28802.external(i32 %0)
291 ret i32 %call
292 }
293
294 define i32 @PR28802() {
295 entry:
296 %call = call i32 @PR28802.callee()
297 ret i32 %call
298 }
299
300 ; CHECK-LABEL: define i32 @PR28802(
301 ; CHECK: call i32 @PR28802.external(i32 0)
302 ; CHECK: ret i32 0
303
304 define internal i32 @PR28848.callee(i32 %p2, i1 %c) {
305 entry:
306 br i1 %c, label %cond.end, label %cond.true
307
308 cond.true:
309 br label %cond.end
310
311 cond.end:
312 %cond = phi i32 [ 0, %cond.true ], [ %p2, %entry ]
313 %or = or i32 %cond, %p2
314 ret i32 %or
315 }
316
317 define i32 @PR28848() {
318 entry:
319 %call = call i32 @PR28848.callee(i32 0, i1 false)
320 ret i32 %call
321 }
322 ; CHECK-LABEL: define i32 @PR28848(
323 ; CHECK: ret i32 0