diff options
Diffstat (limited to 'llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp')
| -rw-r--r-- | llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp index e640d8fa03b..bfa836cd7f7 100644 --- a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp +++ b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp @@ -113,7 +113,11 @@ class IRPromoter { SmallPtrSet<Value*, 8> Promoted; Module *M = nullptr; LLVMContext &Ctx; + // The type we promote to: always i32 IntegerType *ExtTy = nullptr; + // The type of the value that the search began from, either i8 or i16. + // This defines the max range of the values that we allow in the promoted + // tree. IntegerType *OrigTy = nullptr; SmallPtrSetImpl<Value*> *Visited; SmallPtrSetImpl<Value*> *Sources; @@ -326,7 +330,7 @@ bool ARMCodeGenPrepare::isSafeOverflow(Instruction *I) { // - (255 >= 254) == (0xFFFFFFFF >= 254) == true // // To demonstrate why we can't handle increasing values: - // + // // %add = add i8 %a, 2 // %cmp = icmp ult i8 %add, 127 // @@ -604,7 +608,7 @@ void IRPromoter::PromoteTree() { if (!shouldPromote(I) || SafeToPromote->count(I) || NewInsts.count(I)) continue; - + assert(EnableDSP && "DSP intrinisc insertion not enabled!"); // Replace unsafe instructions with appropriate intrinsic calls. @@ -685,10 +689,10 @@ void IRPromoter::Cleanup() { // Some zexts will now have become redundant, along with their trunc // operands, so remove them for (auto V : *Visited) { - if (!isa<CastInst>(V)) + if (!isa<ZExtInst>(V)) continue; - auto ZExt = cast<CastInst>(V); + auto ZExt = cast<ZExtInst>(V); if (ZExt->getDestTy() != ExtTy) continue; @@ -700,9 +704,11 @@ void IRPromoter::Cleanup() { continue; } - // For any truncs that we insert to handle zexts, we can replace the - // result of the zext with the input to the trunc. - if (NewInsts.count(Src) && isa<ZExtInst>(V) && isa<TruncInst>(Src)) { + // Unless they produce a value that is narrower than ExtTy, we can + // replace the result of the zext with the input of a newly inserted + // trunc. + if (NewInsts.count(Src) && isa<TruncInst>(Src) && + Src->getType() == OrigTy) { auto *Trunc = cast<TruncInst>(Src); assert(Trunc->getOperand(0)->getType() == ExtTy && "expected inserted trunc to be operating on i32"); |

