This is an archive of the discontinued LLVM Phabricator instance.

[x86] try to keep FP casted+truncated+extracted vector element out of GPRs
ClosedPublic

Authored by spatel on Jul 14 2019, 1:09 PM.

Details

Summary

inttofp (trunc (extelt X, 0)) --> inttofp (extelt (bitcast X), 0)

We have pseudo-vectorization of scalar int to FP casts, so this tries to make that more likely by replacing a truncate with a bitcast. I didn't see any test diffs starting from 'uitofp', so I left that as a TODO. We can't only match the shorter trunc+extract pattern because there's an opposing transform somewhere, so we infinite loop.

A motivating case is shown in PR39975 and included in the test diffs here:
https://bugs.llvm.org/show_bug.cgi?id=39975

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Jul 14 2019, 1:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2019, 1:09 PM
RKSimon added inline comments.Jul 14 2019, 1:56 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
42410 ↗(On Diff #209746)

Could this be folded into vectorizeExtractedCast (which is done at lowering)?

spatel marked an inline comment as done.Jul 15 2019, 5:10 AM
spatel added inline comments.
llvm/lib/Target/X86/X86ISelLowering.cpp
42410 ↗(On Diff #209746)

I did an experiment that just moved this code as-is to be called at lowering rather than combining, and we miss all but the last 2 test diffs in this patch. I didn't check to see how the other tests mutated, but clearly we'd have to match more patterns if we wait until lowering if we wanted to get those other cases. I can investigate more if that seems like the better option.

My reason for doing the transform earlier is that we know vector bitcasts are generally free if produced early. If created later, they tend to interfere with other pattern matching.

RKSimon accepted this revision.Jul 15 2019, 5:55 AM

LGTM

llvm/lib/Target/X86/X86ISelLowering.cpp
42410 ↗(On Diff #209746)

OK - for now adding a TODO suggesting we merge this with vectorizeExtractedCast is acceptable - we already have a TODO there about supporting SIGN/ZERO_EXTEND so TRUNCATE as well would make sense.

This revision is now accepted and ready to land.Jul 15 2019, 5:55 AM
This revision was automatically updated to reflect the committed changes.