diff options
| author | chenglin.bi <chenglin.bi@linaro.org> | 2022-11-09 05:07:44 +0800 |
|---|---|---|
| committer | chenglin.bi <chenglin.bi@linaro.org> | 2022-11-09 05:08:01 +0800 |
| commit | 597f44409236bf7fa933a4ce18af23772e28fb43 (patch) | |
| tree | 7f57964af50c1bcce50408d6154d695cbfdc7f4e /llvm/lib/CodeGen/TypePromotion.cpp | |
| parent | 1984f01acf5d5d62147b5dfd9871168f69a4858d (diff) | |
[TypePromotion] Replace Zext to Truncate for the case src bitwidth is larger
Fix: https://github.com/llvm/llvm-project/issues/58843
Reviewed By: samtebbs
Differential Revision: https://reviews.llvm.org/D137613
Diffstat (limited to 'llvm/lib/CodeGen/TypePromotion.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/TypePromotion.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp index 6a747a31eabd..6903e9f645c7 100644 --- a/llvm/lib/CodeGen/TypePromotion.cpp +++ b/llvm/lib/CodeGen/TypePromotion.cpp @@ -578,7 +578,8 @@ void IRPromoter::TruncateSinks() { void IRPromoter::Cleanup() { LLVM_DEBUG(dbgs() << "IR Promotion: Cleanup..\n"); // Some zexts will now have become redundant, along with their trunc - // operands, so remove them + // operands, so remove them. + // Some zexts need to be replaced with truncate if src bitwidth is larger. for (auto *V : Visited) { if (!isa<ZExtInst>(V)) continue; @@ -593,6 +594,11 @@ void IRPromoter::Cleanup() { << "\n"); ReplaceAllUsersOfWith(ZExt, Src); continue; + } else if (ZExt->getSrcTy()->getScalarSizeInBits() > PromotedWidth) { + IRBuilder<> Builder{ZExt}; + Value *Trunc = Builder.CreateTrunc(Src, ZExt->getDestTy()); + ReplaceAllUsersOfWith(ZExt, Trunc); + continue; } // We've inserted a trunc for a zext sink, but we already know that the |
