[llvm] [TypePromotion] Support positive addition amounts in isSafeWrap. (PR #81690)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 20:07:49 PST 2024


================
@@ -356,15 +351,23 @@ bool TypePromotionImpl::isSafeWrap(Instruction *I) {
   APInt OverflowConst = cast<ConstantInt>(I->getOperand(1))->getValue();
   if (Opc == Instruction::Sub)
     OverflowConst = -OverflowConst;
-  if (!OverflowConst.isNonPositive())
-    return false;
+
+  // If the constant is positive, we will end up filling the promoted bits with
+  // all 1s. Make sure that results in a cheap add constant.
+  if (!OverflowConst.isNonPositive()) {
+    // We don't have the true promoted width, just use 64 so we can create an
+    // int64_t for the isLegalAddImmediate call.
+    if (OverflowConst.getBitWidth() >= 64)
----------------
AtariDreams wrote:

I personally think we should use the data layout because ARM Thumb is one of those platforms where 64 bit math is extremely cumbersome and expensive. 



https://github.com/llvm/llvm-project/pull/81690


More information about the llvm-commits mailing list