[PATCH] D113495: [TypePromotion] Fix a hardcoded use of 32 as the size being promoted to.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 09:58:23 PST 2021


craig.topper updated this revision to Diff 385866.
craig.topper added a comment.

Update comment as well


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113495/new/

https://reviews.llvm.org/D113495

Files:
  llvm/lib/CodeGen/TypePromotion.cpp


Index: llvm/lib/CodeGen/TypePromotion.cpp
===================================================================
--- llvm/lib/CodeGen/TypePromotion.cpp
+++ llvm/lib/CodeGen/TypePromotion.cpp
@@ -281,7 +281,7 @@
   // wrap in respect to itself in the original bitwidth. If it doesn't wrap,
   // just underflows the range, the icmp would give the same result whether the
   // result has been truncated or not. We calculate this by:
-  // - Zero extending both constants, if needed, to 32-bits.
+  // - Zero extending both constants, if needed, to RegisterBitWidth.
   // - Take the absolute value of I's constant, adding this to the icmp const.
   // - Check that this value is not out of range for small type. If it is, it
   //   means that it has underflowed enough to wrap around the icmp constant.
@@ -359,11 +359,8 @@
     return false;
 
   // Now check that the result can't wrap on itself.
-  APInt Total = ICmpConst->getValue().getBitWidth() < 32 ?
-    ICmpConst->getValue().zext(32) : ICmpConst->getValue();
-
-  Total += OverflowConst->getValue().getBitWidth() < 32 ?
-    OverflowConst->getValue().abs().zext(32) : OverflowConst->getValue().abs();
+  APInt Total = ICmpConst->getValue().zextOrSelf(RegisterBitWidth);
+  Total += OverflowConst->getValue().abs().zextOrSelf(RegisterBitWidth);
 
   APInt Max = APInt::getAllOnes(TypePromotion::TypeSize);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113495.385866.patch
Type: text/x-patch
Size: 1365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211109/2d6b2db9/attachment.bin>


More information about the llvm-commits mailing list