Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h | ||
---|---|---|
544 | This comment suggests that "n" is the same value on the LHS and the RHS, which is not true. | |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
4155 | You don't want a "one use" check for a constant. | |
4161 | I think it would be better to combine this and the previous mi_match into one large match expression. | |
4163–4164 | Since ShlAmt is signed don't you also need to check it's >= 0? (TBH I'm not sure how C++ compares int64_t vs unsigned.) Anyway you might be able to simplify some of the bounds checking. I think all you need to check is: 0 <= ShlAmt <= ShrAmt < Size. Then the checks on Width and Pos should be unnecessary by construction. | |
4169 | This is just Size - ShrAmt! |
How does this new combine interact with matchAshrShlToSextInreg? If n==k, aren't they both trying to combine the same thing with different results?
In that case they would indeed try to combine the same thing. Looks like SextInreg combine has a higher precedence, as no other tests were affected. Should we skip this new combine if n==k?
Looks like SextInreg combine has a higher precedence, as no other tests were affected. Should we skip this new combine if n==k?
I don't know! Is there a well defined way of ensuring that SextInreg has higher precedence? Or is it just luck?
(Actually from an engineering perspective I would prefer that we just have a single combine, that generates sext_inreg if signed&&n==k and sbfx/ubfx otherwise. But I'm not sure that other globalisel folks would agree.)
AFAIK the order of the combines depends on the order in Combine.td. But I'm not sure if that's something we should rely on here and I would argue that G_SEXT_INREG should be preferred over G_SBFX. I have updated the patch to skip the combine if ShlAmt == ShrAmt.
But just in case, let's wait until tomorrow to give the others a chance to voice their opinion.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
4161 | This will also skip the unsigned n==k case, which you probably do want to turn into ubfx? |
do not skip ubfx combine if shift sizes match
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
4161 | Yep, was a bit too trigger happy :) Fixed now. |
LGTM apart from the question inline.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
4145 | Lots of combines use isLegalOrBeforeLegalizer, i.e. they do apply before legalization. Is there a reason you have made this one different, so it does not apply before legalization? |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
4145 | For that I followed the other bitfield extract combine. I'm guessing because there is only widenScalar implemented for G_SBFX and G_UBFX, so you wouldn't even be able to lower it if it would be illegal for your target. Once at least the lower action is implemented, this check can be changed to make this combine also run before the legalizer. |
This comment suggests that "n" is the same value on the LHS and the RHS, which is not true.