This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fold vecreduce_xor/or/and(splat_vector(val)) to constant
Needs RevisionPublic

Authored by Jimerlife on Aug 19 2022, 12:03 AM.

Details

Summary

fold vecreduce_or/and(splat_vector(val)) -> constant val
fold vecreduce_xor(splat_vector(val)) -> constant zero

Precommit tests D132207

Diff Detail

Event Timeline

Jimerlife created this revision.Aug 19 2022, 12:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2022, 12:03 AM
Jimerlife requested review of this revision.Aug 19 2022, 12:03 AM

XOR will be 0 or val depending on if there are an even number of vector elements.

Can you add some tests for both cases?

Do you have real world examples of C code where this occurs?

Would this be better to do in InstCombine?

Where are the test deltas?

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
23506

What if the element count is odd?

Do you have real world examples of C code where this occurs?

Would this be better to do in InstCombine?

Where are the test deltas?

I have no real world examples of C code, just think could fold this. I am not sure if this is better to do in InstCombine. I create precommit tests D132207, but this test does't consider vector element count. Element count should also be consider.

XOR will be 0 or val depending on if there are an even number of vector elements.

Can you add some tests for both cases?

You are right, should consider element count. Thank you.

This might be more useful if you did it in SelectionDAG::computeKnownBits - then it'd work for any case with common bits in every vector element and you'd get constant folding as well.

Hi @Jimerlife, I think it's common practice to create a chain of patches in your downstream repo where the code change patch is based off the pre-committed test patch. That way we can observe the change in behaviour as part of this patch without having to wait for a rebase. You can edit the parent revision to add the pre-commit as a parent so the chain is clear in Phabricator.

RKSimon requested changes to this revision.Aug 19 2022, 6:10 AM
This revision now requires changes to proceed.Aug 19 2022, 6:10 AM