This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG][RISCV] Use isSExtCheaperThanZExt to control whether sext or zext is used for constant folding any_extend.
ClosedPublic

Authored by craig.topper on Jul 13 2021, 10:52 AM.

Details

Summary

RISCV would prefer a sign extended constant since that works better
with our constant materialization. We have an existing TLI hook we
use to control sign extension of setcc operands in type legalization.
That hook happens to do the right check we need here, but might be
straying from its original purpose. With only RISCV defining this
hook in tree, I wasn't sure if it was worth adding another hook
with identical behavior.

This is an alternative to D105785 where I tried to handle this in
the RISCV backend by not creating ANY_EXTENDs in some places.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 13 2021, 10:52 AM
craig.topper requested review of this revision.Jul 13 2021, 10:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2021, 10:52 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

I think re-using the hook is fine. The existing uses are about any value of that type, whereas this use is about a specific value of that type which _might_ have a different answer, but until a situation arises where the distinction is important adding a new hook seems unnecessary.

Rebase tests. Drop commentary about the hook from the source code.

frasercrmck accepted this revision.Jul 19 2021, 1:24 AM

LGTM. I also think re-using the hook is fine, at least until there's something that requires something else.

This revision is now accepted and ready to land.Jul 19 2021, 1:24 AM
This revision was landed with ongoing or failed builds.Jul 19 2021, 9:25 AM
This revision was automatically updated to reflect the committed changes.