[llvm] 0963291 - [TypePromotion] Fix a hardcoded use of 32 as the size being promoted to.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 10 22:12:46 PST 2021
Author: Craig Topper
Date: 2021-11-10T22:12:39-08:00
New Revision: 096329199125d4b14cf12b86d89449c274ce9f36
URL: https://github.com/llvm/llvm-project/commit/096329199125d4b14cf12b86d89449c274ce9f36
DIFF: https://github.com/llvm/llvm-project/commit/096329199125d4b14cf12b86d89449c274ce9f36.diff
LOG: [TypePromotion] Fix a hardcoded use of 32 as the size being promoted to.
At least I think that's what the 32 here is. Use RegisterBitWidth
instead.
While there replace zext with zextOrSelf to simplify the code.
Reviewed By: samparker, dmgreen
Differential Revision: https://reviews.llvm.org/D113495
Added:
Modified:
llvm/lib/CodeGen/TypePromotion.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index bad5a033bd1a..782d7eed27a6 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -281,7 +281,7 @@ bool TypePromotion::isSafeWrap(Instruction *I) {
// 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,25 +359,16 @@ bool TypePromotion::isSafeWrap(Instruction *I) {
return false;
// Now check that the result can't wrap on itself.
- APInt Total = ICmpConst->getValue().getBitWidth() < 32 ?
- ICmpConst->getValue().zext(32) : ICmpConst->getValue();
+ APInt Total = ICmpConst->getValue().zextOrSelf(RegisterBitWidth);
+ Total += OverflowConst->getValue().abs().zextOrSelf(RegisterBitWidth);
- Total += OverflowConst->getValue().getBitWidth() < 32 ?
- OverflowConst->getValue().abs().zext(32) : OverflowConst->getValue().abs();
+ APInt Max = APInt::getAllOnes(TypeSize).zextOrSelf(RegisterBitWidth);
- APInt Max = APInt::getAllOnes(TypePromotion::TypeSize);
-
- if (Total.getBitWidth() > Max.getBitWidth()) {
- if (Total.ugt(Max.zext(Total.getBitWidth())))
- return false;
- } else if (Max.getBitWidth() > Total.getBitWidth()) {
- if (Total.zext(Max.getBitWidth()).ugt(Max))
- return false;
- } else if (Total.ugt(Max))
+ if (Total.ugt(Max))
return false;
- LLVM_DEBUG(dbgs() << "IR Promotion: Allowing safe overflow for "
- << *I << "\n");
+ LLVM_DEBUG(dbgs() << "IR Promotion: Allowing safe overflow for " << *I
+ << "\n");
SafeWrap.push_back(I);
return true;
}
More information about the llvm-commits
mailing list