This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Describe defs/uses of VLLDM and VLSTM
ClosedPublic

Authored by chill on Jun 10 2020, 9:47 AM.

Details

Summary

The VLLDM and VLSTM instructions are incompletely specified. They (potentially)
write (or read, respectively) registers Q0-Q7, VPR, and FPSCR, but the compiler
is unaware of it.

In the new test case cmse-vlldm-no-reorder.ll case the compiler missed an
anti-dependency and reordered a VLLDM ahead of the instruction, which stashed
the return value from the non-secure call, effectively clobbering said
value.

This test case does not fail with upstream LLVM, because of scheduling
differences and I couldn't find a test case for the VLSTM either.

Diff Detail

Event Timeline

chill created this revision.Jun 10 2020, 9:47 AM
efriedma added inline comments.Jun 10 2020, 11:27 AM
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
1285

RegState::Undef seems wrong: presumably the registers may actually contain data we need to preserve, or we wouldn't bother saving them in the first place.

chill marked an inline comment as done.Jun 10 2020, 12:49 PM
chill added inline comments.
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
1285

Saving/restoring is fine even if we didn't have to.

The "undef" is because we don't want to require the register to be defined at the point before the vlstm. Defined or not, we save then restore, don't care about values.

Otherwise, the machine verifier complains about the use of undefined register.

Is it possible for the scheduler to reorder a def after the "undef"-ed use in vlstm ? If yes, indeed, that'd be a problem, in which case maybe we can just set the insn as a scheduling barrier.

efriedma added inline comments.Jun 10 2020, 1:14 PM
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
1285

Generally, registers which are explicitly saved by the callee are part of the live-in list of the entry block. The "definition" comes from the caller. I would expect save/restore of the FP registers here to work the same way.

chill updated this revision to Diff 270405.Jun 12 2020, 8:07 AM

Updated to take into account liveness of registers. Whenever we blanket push registers, the live ones are ordinary operands,
the dead ones are Undef operands.

chill marked 2 inline comments as done.Jun 19 2020, 12:47 AM

PIng.

Can you add a testcase showing the MIR before/after ARMExpandPseudoInsts?

chill updated this revision to Diff 272460.Jun 22 2020, 8:53 AM
This revision is now accepted and ready to land.Jun 22 2020, 12:22 PM
This revision was automatically updated to reflect the committed changes.