[PATCH] D108475: Fix late rematerialization operands check

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 20 10:50:20 PDT 2021


rampitec created this revision.
rampitec added reviewers: dmgreen, kparzysz, qcolombet, stoklund.
Herald added subscribers: hiraditya, MatzeB.
rampitec requested review of this revision.
Herald added a project: LLVM.

D106408 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D106408> but needed to reland
reverted D106408 <https://reviews.llvm.org/D106408>.


https://reviews.llvm.org/D108475

Files:
  llvm/lib/CodeGen/LiveRangeEdit.cpp
  llvm/test/CodeGen/AArch64/pr51516.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108475.367832.patch
Type: text/x-patch
Size: 5173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210820/a131e775/attachment-0001.bin>


More information about the llvm-commits mailing list