[llvm] [DAG] ISD::matchUnaryPredicate / matchUnaryFpPredicate / matchBinaryPredicate - add DemandedElts variant (PR #183013)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 2 04:47:46 PDT 2026
VachanVY wrote:
@RKSimon @arsenm
Could you please guide me on how to proceed? Either we go back to old way of switch/vector handling or have `AllowTruncation` has true because of the failing tests. I couldn't come up with anything else.
```cpp
bool SelectionDAG::isKnownToBeAPowerOfTwo(SDValue Val,
const APInt &DemandedElts,
bool OrZero, unsigned Depth) const {
...
// Is the constant a known power of 2 or zero?
if (ISD::matchUnaryPredicate(Val, DemandedElts, IsPowerOfTwoOrZero,
/*AllowUndefs=*/false, /*AllowTruncation=*/true))
return true;
...
}
```
```
Failed Tests (3):
LLVM :: CodeGen/RISCV/rvv/fshr-fshl-vp.ll
LLVM-Unit :: Target/AArch64/./AArch64Tests.exe/AArch64SelectionDAGTest/KnownToBeAPowerOfTwo_Constants
LLVM-Unit :: Target/AArch64/./AArch64Tests.exe/AArch64SelectionDAGTest/KnownToBeAPowerOfTwo_Select
```
As I said earlier:
> I think we need to keep AllowTruncation=true here because this call is replacing the previous explicit vector constant handling in isKnownToBeAPowerOfTwo.
Without AllowTruncation, matchUnaryPredicate rejects BUILD_VECTOR/SPLAT_VECTOR constants whose stored constant type differs from the vector scalar type, for example i32 constants used to build a v2i16. The predicate itself already does zextOrTrunc(BitWidth), so accepting those constants is intentional and matches the behavior of the removed switch/vector handling.
https://github.com/llvm/llvm-project/pull/183013
More information about the llvm-commits
mailing list