[PATCH] D127801: [InstCombine] convert mask and shift of power-of-2 to cmp+select
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 14 21:25:27 PDT 2022
bcl5980 added a comment.
I agree with that the transform is more general. And my question is how to invert the transform on backend if shift + and is faster.
For now SelectionDag has the transform `select Cond, Pow2, 0 --> (zext Cond) << log2(Pow2)`
// select Cond, Pow2, 0 --> (zext Cond) << log2(Pow2)
if (C1Val.isPowerOf2() && C2Val.isZero()) {
if (VT != MVT::i1)
Cond = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, Cond);
SDValue ShAmtC =
DAG.getShiftAmountConstant(C1Val.exactLogBase2(), VT, DL);
return DAG.getNode(ISD::SHL, DL, VT, Cond, ShAmtC);
}
And if we want to do this
`X == (log2(C) - log2(ShiftC)) ? C : 0 --> (ShiftC << X) & C`
`X == (log2(ShiftC) - log2(C)) ? C : 0 --> (ShiftC >> X) & C`
We need to assume `X < BitWidth` https://alive2.llvm.org/ce/z/-GjVsu
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127801/new/
https://reviews.llvm.org/D127801
More information about the llvm-commits
mailing list