[PATCH] D131487: [TypePromotion] Don't insert Truncate for a no-op ZExt

Andre Vieira via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 04:55:49 PDT 2022


avieira created this revision.
avieira added reviewers: dmgreen, SjoerdMeijer, fhahn, efriedma, rnk, samparker, adriantong1024.
Herald added a subscriber: hiraditya.
Herald added a project: All.
avieira requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Hi,

As the title says, I don't believe there's a point in inserting Truncates before ZExt's that have no-effect, i.e. ZExts where the argument's type width is the same as the result's type width.

This is a prerequisite for the test in D111237 <https://reviews.llvm.org/D111237> to pass.


https://reviews.llvm.org/D131487

Files:
  llvm/lib/CodeGen/TypePromotion.cpp
  llvm/test/Transforms/TypePromotion/AArch64/phi-zext-gep.ll


Index: llvm/test/Transforms/TypePromotion/AArch64/phi-zext-gep.ll
===================================================================
--- llvm/test/Transforms/TypePromotion/AArch64/phi-zext-gep.ll
+++ llvm/test/Transforms/TypePromotion/AArch64/phi-zext-gep.ll
@@ -24,7 +24,6 @@
 ; CHECK-NEXT:    br label [[FOR_END]]
 ; CHECK:       for.end:
 ; CHECK-NEXT:    [[TAG_0_IN_LCSSA:%.*]] = phi i32 [ [[TMP0]], [[ENTRY:%.*]] ], [ [[TMP1]], [[FOR_END_LOOPEXIT]] ]
-; CHECK-NEXT:    [[TMP2:%.*]] = trunc i32 [[TAG_0_IN_LCSSA]] to i8
 ; CHECK-NEXT:    ret i32 [[TAG_0_IN_LCSSA]]
 ;
 entry:
Index: llvm/lib/CodeGen/TypePromotion.cpp
===================================================================
--- llvm/lib/CodeGen/TypePromotion.cpp
+++ llvm/lib/CodeGen/TypePromotion.cpp
@@ -551,8 +551,11 @@
     }
 
     // Don't insert a trunc for a zext which can still legally promote.
+    // Nor insert a trunc for a zext with the same input type as output, this
+    // was a zext that was part of a promotion mutation and will be removed
+    // after.
     if (auto ZExt = dyn_cast<ZExtInst>(I))
-      if (ZExt->getType()->getScalarSizeInBits() > PromotedWidth)
+      if (ZExt->getType()->getScalarSizeInBits() >= PromotedWidth)
         continue;
 
     // Now handle the others.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131487.451113.patch
Type: text/x-patch
Size: 1274 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220809/841417c2/attachment.bin>


More information about the llvm-commits mailing list