This is an archive of the discontinued LLVM Phabricator instance.

[RFC] AMDGPU: add execfix flag to SI_ELSE
ClosedPublic

Authored by nhaehnle on Jul 27 2016, 12:13 AM.

Details

Summary

SI_ELSE is lowered into two parts:

s_or_saveexec_b64 dst, src (at the start of the basic block)

s_xor_b64 exec, exec, dst (at the end of the basic block)

The idea is that dst contains the exec mask of the preceding IF block. It can
happen that SIWholeQuadMode decides to switch from WQM to Exact mode inside
the basic block that contains SI_ELSE, in which case it introduces an instruction

s_and_b64 exec, exec, s[...]

which masks out bits that can correspond to both the IF and the ELSE paths.
So the resulting sequence must be:

s_or_savexec_b64 dst, src

s_and_b64 exec, exec, s[...] <-- added by SIWholeQuadMode
s_and_b64 dst, dst, exec <-- added by SILowerControlFlow

s_xor_b64 exec, exec, dst

Whether to add the additional s_and_b64 dst, dst, exec is currently determined
via the ExecModified tracking. With this change, it is instead determined by
an additional flag on SI_ELSE which is set by SIWholeQuadMode.

Finally: It also occured to me that an alternative approach for the long run
is for SILowerControlFlow to unconditionally emit

s_or_saveexec_b64 dst, src

...

s_and_b64 dst, dst, exec
s_xor_b64 exec, exec, dst

and have a pass that detects and cleans up the "redundant AND with exec"
pattern where possible. This could be useful anyway, because we also add
instructions

s_and_b64 vcc, exec, vcc

before s_cbranch_scc (in moveToALU), and those are often redundant. I have
some pending changes to how KILL is lowered that could also benefit from
such a cleanup pass.

In any case, this current patch could help in the short term with the whole
ExecModified business.

Diff Detail

Repository
rL LLVM

Event Timeline

nhaehnle updated this revision to Diff 65671.Jul 27 2016, 12:13 AM
nhaehnle retitled this revision from to [RFC] AMDGPU: add execfix flag to SI_ELSE.
nhaehnle updated this object.
nhaehnle added a reviewer: arsenm.
nhaehnle added a subscriber: llvm-commits.
arsenm accepted this revision.Jul 27 2016, 11:31 AM
arsenm edited edge metadata.

LGTM, except for the operand type. Also, can you add a test which shows a change from moving the modifiesRegister so that it doesn't also count the else (since I think this should fix it?)

lib/Target/AMDGPU/SIInstructions.td
1954 ↗(On Diff #65671)

This should be i1imm instead of SSrc since it's just an immediate

This revision is now accepted and ready to land.Jul 27 2016, 11:31 AM
This revision was automatically updated to reflect the committed changes.