[PATCH] D112298: [InstCombine] Generalize sadd.sat combine to compute sign bits.

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 4 05:27:30 PDT 2021


dmgreen added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:2319-2322
+  unsigned NeededSignBits =
+      AddSub->getType()->getScalarSizeInBits() - NewBitWidth + 1;
+  if (ComputeNumSignBits(AddSub->getOperand(0), 0, AddSub) < NeededSignBits ||
+      ComputeNumSignBits(AddSub->getOperand(1), 0, AddSub) < NeededSignBits)
----------------
lebedev.ri wrote:
> I've spent more time trying to reason about this, which means this can be improved.
> Please add `ComputeMinSignedBits()` wrapper next to `ComputeNumSignBits()`,
> and use it here. Then this becomes
> ```
>   if (ComputeMinSignedBits(AddSub->getOperand(0), 0, AddSub) > NewBitWidth ||
>       ComputeMinSignedBits(AddSub->getOperand(1), 0, AddSub) > NewBitWidth)
> ```
> which at least to me is immensely more readable.
Sounds good. Do you mean next to the ComputeNumSignBits in InstCombiner, or next to the base variant in ValueTracking?

I added it to InstCombiner for the moment, but can easily move it if you think that is better.


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

https://reviews.llvm.org/D112298



More information about the llvm-commits mailing list