diff options
author | Juergen Ributzka <juergen@apple.com> | 2014-04-22 18:06:58 +0000 |
---|---|---|
committer | Juergen Ributzka <juergen@apple.com> | 2014-04-22 18:06:58 +0000 |
commit | b95412cc24e99a72ee3efc05a14995bb508f3a23 (patch) | |
tree | e1f874978061a15d38f1f8f8965ec04f4774b039 /lib | |
parent | 0db2ba1ce88fa705ae48e200cc020d1539ed11ec (diff) | |
download | llvm-b95412cc24e99a72ee3efc05a14995bb508f3a23.tar.gz llvm-b95412cc24e99a72ee3efc05a14995bb508f3a23.tar.bz2 llvm-b95412cc24e99a72ee3efc05a14995bb508f3a23.tar.xz |
[Constant Hoisting] Materialize the constant before the cloned cast instruction.
In the case where the constant comes from a cloned cast instruction, the
materialization code has to go before the cloned cast instruction.
This commit fixes the method that finds the materialization insertion point
by making it aware of this case.
This fixes <rdar://problem/15532441>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206913 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/ConstantHoisting.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/ConstantHoisting.cpp b/lib/Transforms/Scalar/ConstantHoisting.cpp index 9b7ed816ad..af0450729a 100644 --- a/lib/Transforms/Scalar/ConstantHoisting.cpp +++ b/lib/Transforms/Scalar/ConstantHoisting.cpp @@ -207,7 +207,16 @@ bool ConstantHoisting::runOnFunction(Function &Fn) { /// \brief Find the constant materialization insertion point. Instruction *ConstantHoisting::findMatInsertPt(Instruction *Inst, unsigned Idx) const { - // The simple and common case. + // If the operand is a cast instruction, then we have to materialize the + // constant before the cast instruction. + if (Idx != ~0U) { + Value *Opnd = Inst->getOperand(Idx); + if (auto CastInst = dyn_cast<Instruction>(Opnd)) + if (CastInst->isCast()) + return CastInst; + } + + // The simple and common case. This also includes constant expressions. if (!isa<PHINode>(Inst) && !isa<LandingPadInst>(Inst)) return Inst; @@ -229,7 +238,7 @@ findConstantInsertionPoint(const ConstantInfo &ConstInfo) const { SmallPtrSet<BasicBlock *, 8> BBs; for (auto const &RCI : ConstInfo.RebasedConstants) for (auto const &U : RCI.Uses) - BBs.insert(U.Inst->getParent()); + BBs.insert(findMatInsertPt(U.Inst, U.OpndIdx)->getParent()); if (BBs.count(Entry)) return &Entry->front(); |