This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Turn pred_cast(xor(x, -1)) into xor(pred_cast(x), -1)
ClosedPublic

Authored by dmgreen on Nov 27 2020, 8:19 AM.

Details

Summary

This folds a not (an xor -1) though a predicate_cast, so that it can be turned into a VPNOT and potentially be folded away as an "else" predicate inside a VPT block.

Diff Detail

Event Timeline

dmgreen created this revision.Nov 27 2020, 8:19 AM
dmgreen requested review of this revision.Nov 27 2020, 8:19 AM
simon_tatham added inline comments.Nov 30 2020, 2:35 AM
llvm/lib/Target/ARM/ARMISelLowering.cpp
13855

VPT predicates are only 16 bits wide, so I think we could legally apply this to any constant XOR that has the bottom 16 bits set, not just 0xFFFFFFFF.

In case somebody wrote out pred ^ 0xFFFF longhand in source code, would it be better to do that?

dmgreen added inline comments.Dec 1 2020, 12:58 AM
llvm/lib/Target/ARM/ARMISelLowering.cpp
13855

Thanks for taking a look. Long story short, the rest of llvm will like to convert xor i32 x, 0xffff to xor i32 x, -1 as it represents a not and is simpler to deal with. Because we tell it that the demanded bits of a PRED_CAST are the lower bits, it will do that transform for us and here we only need to check for a full mask.

There is a isBitwiseNot helper function though, which will do this for us. I'll change it to use that and add an extra test.

dmgreen updated this revision to Diff 308567.Dec 1 2020, 12:59 AM

Use isBitwiseNot and add an extra test.

simon_tatham accepted this revision.Dec 1 2020, 1:49 AM
simon_tatham added inline comments.
llvm/test/CodeGen/Thumb2/mve-pred-constfold.ll
107

(Incidentally, it's a shame this one couldn't have ended up removing the VPNOT completely and just swapping round the operands of the VPSEL!)

This revision is now accepted and ready to land.Dec 1 2020, 1:49 AM
avieira added a subscriber: avieira.

Accidentally linked my commit of https://reviews.llvm.org/D92236 to this revision. Apologies.