[PATCH] D112298: [InstCombine] Generalize sadd.sat combine to compute sign bits.
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 3 11:57:45 PDT 2021
lebedev.ri added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:2316-2317
+ // The two operands of the add/sub need to contain at least enough sign bits
+ // to be valid in the NewBitWidth. This is usually achieved via a sext from a
+ // smaller type.
----------------
================
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)
----------------
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.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112298/new/
https://reviews.llvm.org/D112298
More information about the llvm-commits
mailing list