This is an archive of the discontinued LLVM Phabricator instance.

Fix late rematerialization operands check
ClosedPublic

Authored by rampitec on Aug 20 2021, 10:50 AM.

Details

Summary

D106408 enables rematerialization of instructions with virtual
register uses. That has uncovered the bug in the allUsesAvailableAt
implementation: https://bugs.llvm.org/show_bug.cgi?id=51516.

In the majority of cases canRematerializeAt() called to check if
an instruction can be rematerialized before the given UseIdx.
However, SplitEditor::enterIntvAtEnd() calls it to rematerialize
an instruction at the end of a block passing LIS.getMBBEndIdx()
into the check. In the testcase from the bug it has attempted to
rematerialize ADDXri after STRXui in bb.17. The use operand %55
of the ADD is killed by the STRX but that is undetected by the check
because it adjusts passed UseIdx to the reg slot, before the kill.
The value is dead at the index passed to the check however.

This change uses a later of passed UseIdx and its reg slot. This
shall be correct because if are checking an availability of operands
before an instruction that instruction cannot be the one defining
these operands. If we are checking for late rematerialization we
are really interested if operands live past the instruction.

The bug is not exploitable without D106408 but needed to reland
reverted D106408.

Diff Detail

Event Timeline

rampitec created this revision.Aug 20 2021, 10:50 AM
rampitec requested review of this revision.Aug 20 2021, 10:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2021, 10:50 AM
rampitec updated this revision to Diff 367884.Aug 20 2021, 1:44 PM

Added AMDGPU test which fails on just the trunk without D106408.

dmgreen accepted this revision.Aug 23 2021, 12:23 AM

Sounds good to me

This revision is now accepted and ready to land.Aug 23 2021, 12:23 AM
This revision was automatically updated to reflect the committed changes.