[PATCH] D138814: [InstCombine] Combine a/lshr of add -> uadd.with.overflow

Pierre van Houtryve via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 00:57:47 PST 2022


Pierre-vh added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:880
+      TruncInst *Trunc = dyn_cast<TruncInst>(U);
+      if (!Trunc || Trunc->getType()->getScalarSizeInBits() > ShAmt)
+        return nullptr;
----------------
lebedev.ri wrote:
> Is there test coverage when the shift amt isn't the half of the original width?
lshr_16_to_64_add_zext_basic?
I also added a couple of test cases where the shift amount is lower/higher than what's desired.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:902-905
+  // Replace the uses of the original add with a zext of the
+  // uaddo's result.
+  if (!Add->hasOneUse())
+    replaceInstUsesWith(*AddInst, Builder.CreateZExt(UAdd, Ty));
----------------
lebedev.ri wrote:
> alive2 proof please? 
At this stage, the add is only used by either ShAmt-sized truncs, or the shift.
We're removing the shift, and for the truncs, they will cancel out.
https://alive2.llvm.org/ce/z/TWQp29


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138814



More information about the llvm-commits mailing list