This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Combine G_ASSERT_*EXT + G_LOAD -> G_S/ZEXTLOAD
AbandonedPublic

Authored by paquette on Aug 2 2021, 1:22 PM.

Details

Reviewers
aemerson
arsenm
Summary

CallLowering can emit hint instructions (G_ASSERT_ZEXT, G_ASSERT_SEXT) to communicate whether or not a parameter/return value is expected to be sign or zero extended.

When we run into one of these along with a G_LOAD, we need to be careful to select the correct type of extended load.

e.g.

https://godbolt.org/z/x3oG4s3MT

In the above example, without this patch, GISel will not emit a sign-extended load. SDAG has the correct behaviour here.

The work here is identical to how we already combine G_SEXT_INREG with G_LOAD. However, because this can be important for ABI-conformance, it needs to run at all optimization levels. So, this is split out into its own combine which runs under combines_for_extload.

Diff Detail

Event Timeline

paquette created this revision.Aug 2 2021, 1:22 PM
paquette requested review of this revision.Aug 2 2021, 1:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2021, 1:22 PM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added a comment.Aug 2 2021, 1:26 PM

It seems to me like you're working around a correctness issue in a combine. The load is incorrect to begin with, you can't fix it up later like this

I don't think this is right. G_ASSERT_SEXT is supposed to only provide information for optimizations about the bits of the source. Using it to justify transforming the source seems the wrong place to fix it. We should be emitting the right kind of load in call lowering.

It seems to me like you're working around a correctness issue in a combine. The load is incorrect to begin with, you can't fix it up later like this

Beat me to it.

paquette abandoned this revision.Aug 2 2021, 2:38 PM

Fixing in AArch64CallLowering in D107313