This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Use pointer type size for offset constant when lowering load/stores
ClosedPublic

Authored by gargaroff on Jan 24 2020, 3:00 AM.

Details

Reviewers
dsanders
arsenm
Summary

Lowering non-power-of-2 G_LOAD/G_STORE introduces a G_PTR_ADD. The offset constant used by this instruction uses 64-bit unconditionally. This causes legalization to fail for backends that don't use 64-bit pointers.

This patch uses the size of the pointer type for the type of the offset constant to fix this problem.

Diff Detail

Event Timeline

gargaroff created this revision.Jan 24 2020, 3:00 AM

I didn't know if and where I can add a proper test for this. If that is required I'd appreciate it if you would point me in the right direction for it.

arsenm accepted this revision.Jan 24 2020, 5:52 AM

While this is correct, this also shouldn't cause legalization to fail with non 64-bit pointers. Are you missing a legalize rule for the second type index for G_PTR_ADD?

This revision is now accepted and ready to land.Jan 24 2020, 5:52 AM

While this is correct, this also shouldn't cause legalization to fail with non 64-bit pointers. Are you missing a legalize rule for the second type index for G_PTR_ADD?

I don't think we do to be honest. This is our legalizer rule for G_PTR_ADD:

getActionDefinitionsBuilder(G_PTR_ADD)
    .legalFor({{p0, s32}})
    .clampScalar(1, s32, s32);

So we try to narrow the 64-bit constant to a 32-bit constant. In the LegalizerHelper::narrowScalar there is no rule for G_PTR_ADD, so it returns with UnableToLegalize.

Could someone with commit access land this for me?