This is an archive of the discontinued LLVM Phabricator instance.

[CGP] Fix the GV handling in complex addressing mode
ClosedPublic

Authored by skatkov on Jan 17 2018, 11:41 PM.

Details

Summary

If in complex addressing mode the difference is in GV then
base reg should not be installed because we plan to use
base reg as a merge point of different GVs.

This is a fix for PR35980.

Diff Detail

Repository
rL LLVM

Event Timeline

skatkov created this revision.Jan 17 2018, 11:41 PM
skatkov edited the summary of this revision. (Show Details)

It looks like the reason we get both BaseGV and BaseReg is that matchScaledValue will use BaseReg when the scale is 1 (and BaseReg isn't already used). It may be worthwhile making it consistently use ScaledReg, as then I don't think we would run into this problem, but fixing things so we don't fail an assertion if we do happen to have both is definitely something we should do.

lib/CodeGen/CodeGenPrepare.cpp
2708–2713 ↗(On Diff #130362)

I think that the logic has gotten complex enough here that it would be clearer to split it up and invert it so we sequentially check for all the things that can't be handled (each with its own comment), something like:

bool CanAdd = true;
// If NewAddrMode differs in only one dimension then we can handle it by...
if (DifferentField == ExtAddrMode::MultipleFields)
  CanAdd = false;
// We can't handle ScaleField
if (DifferentField == ExtAddrMode::ScaleField)
  CanAdd = false;
// We also must reject ...
if (DifferentField == ExtAddrMode::BaseOffsField && NewAddrMode.ScaledReg)
  CanAdd = false;
// We also must reject ...
if (DifferentField == ExtAddrMode::BaseGVField && NewAddrMode.HasBaseReg)
  CanAdd = false;

if (CanAdd)
  AddrModes.emplace_back(NewAddrMode);
else
  AddrModes.clear();

return CanAdd;
test/Transforms/CodeGenPrepare/X86/sink-addrmode-select.ll
2–5 ↗(On Diff #130362)

It doesn't look like changing the datalayout has any effect on the test (and you shouldn't be doing it by commenting out the old one anyway).

skatkov updated this revision to Diff 130828.Jan 21 2018, 10:06 PM

Please take a look.

This revision is now accepted and ready to land.Jan 22 2018, 9:28 AM
This revision was automatically updated to reflect the committed changes.