This is an archive of the discontinued LLVM Phabricator instance.

[X86][SSE] Optimize llvm.experimental.vector.reduce.xor.vXi1 parity reduction (PR38840)
ClosedPublic

Authored by RKSimon on Apr 27 2019, 11:04 AM.

Details

Summary

I think I've got this right.....

An xor reduction of a bool vector can be optimized to a parity check of the MOVMSK/BITCAST'd integer - if the population count is odd return 1, else return 0.

I haven't enabled POPCNT on any of the test targets, but I can if people think it useful (AVX1+ targets would always have POPCNT).

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Apr 27 2019, 11:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2019, 11:04 AM

LGTM. Can try to replace the xor with 0 as a follow or open a bug?

test/CodeGen/X86/vector-reduce-xor-bool.ll
26

Would be nice to use "test %al, %al" or "or %al, %al" or "and %al, %al" here which I think would shorter encoding since there would be no immediate.

36

Would be nice to use the flags from the and.

craig.topper accepted this revision.Apr 27 2019, 11:03 PM
This revision is now accepted and ready to land.Apr 27 2019, 11:03 PM
This revision was automatically updated to reflect the committed changes.