This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes][AArch64][X86] Make type legalization of vector (S/U)ADD/SUB/MULO follow getSetCCResultType for the overflow bits. Make UnrollVectorOverflowOp properly convert from scalar boolean contents to vector boolean contents
ClosedPublic

Authored by craig.topper on Feb 22 2019, 5:37 PM.

Details

Summary

When promoting the over flow vector for these ops we should use the target's desired setcc result type. This way a v8i32 result type will use a v8i32 overflow vector instead of a v8i16 overflow vector. A v8i16 overflow vector will cause LegalizeDAG/LegalizeVectorOps to have to use v8i32 and truncate to v8i16 in its expansion. By doing this in type legalization instead, we get the truncate into the DAG earlier and give DAG combine more of a chance to optimize it.

We also have to fix unrolling to use the scalar setcc result type for the scalarized operation, and convert it to the required vector element type after the scalar operation. We have to observe the vector boolean contents when doing this conversion. The previous code was just taking the scalar result and putting it in the vector. But for X86 and AArch64 that would have only put a the boolean value in bit 0 of the element and left all other bits in the element 0. We need to ensure all bits in the element are the same. I'm using a select with constants here because that's what setcc unrolling in LegalizeVectorOps used.

Diff Detail

Event Timeline

craig.topper created this revision.Feb 22 2019, 5:37 PM
nikic added a comment.Feb 23 2019, 1:09 AM

Sorry for the incorrect unrolling, really messed up there.

lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
605

Should this be getBoolExtOrTrunc()?

lib/CodeGen/SelectionDAG/SelectionDAG.cpp
8987

With this change, you should be able to drop the size check that I added in X86ISelLowering::LowerXALUO().

Use getBoolExtOrTrunc. Remove unneeded code from LowerXALU0

Herald added a project: Restricted Project. · View Herald TranscriptFeb 23 2019, 12:42 PM
nikic accepted this revision.Feb 24 2019, 6:05 AM

LGTM

This revision is now accepted and ready to land.Feb 24 2019, 6:05 AM
This revision was automatically updated to reflect the committed changes.