This is an archive of the discontinued LLVM Phabricator instance.

[globalisel][legalizer] G_LOAD/G_STORE NarrowScalar should not emit G_GEP x, 0.
ClosedPublic

Authored by dsanders on May 2 2017, 6:27 AM.

Details

Summary

When legalizing G_LOAD/G_STORE using NarrowScalar, we should avoid emitting
%0 = G_CONSTANT ty 0
%1 = G_GEP %x, %0
since it's cheaper to not emit the redundant instructions than it is to fold them
away later.

Event Timeline

dsanders created this revision.May 2 2017, 6:27 AM
qcolombet accepted this revision.May 12 2017, 2:15 PM

LGTM modulo a small refactoring to avoid code duplication.

lib/CodeGen/GlobalISel/LegalizerHelper.cpp
288

Could you factorize the code in a helper function?

This revision is now accepted and ready to land.May 12 2017, 2:15 PM
dsanders updated this revision to Diff 100253.May 25 2017, 8:45 AM

Factored out the optimization into MachineIRBuilder.

@qcolombet: Before I commit, I'd just like to double-check that the new
materializeGEP() function in MachineIRBuilder is ok with you. The
materialize*() name is intended to be used for instructions that may have to
create vregs in some cases.

The new helper looks good.
Nitpicks below.

lib/CodeGen/GlobalISel/LegalizerHelper.cpp
249

Is this clang-formated?
In the browser it looks larger than 80-col, but it may just be an impression.

288

Shouldn't we call materializeGEP here too for the whole if-then block?

igorb added inline comments.Jun 13 2017, 12:15 AM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
249

could you calculate offset type base on pointer size ? So it will be legal for 32bit targets .

dsanders closed this revision.Jun 13 2017, 4:43 PM
dsanders added inline comments.Jun 13 2017, 4:45 PM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
249

I've fixed this in the commit.

249

Sure, I've made this change in the commit.

288

I've fixed this in the commit.