This is an archive of the discontinued LLVM Phabricator instance.

PeepholeOptimizer: Do not replace SubregToReg(bitcast like)
ClosedPublic

Authored by MatzeB on Jan 9 2017, 11:42 AM.

Details

Summary

While we can usually replace bitcast like instructions
(MachineInstr::isBitcast()) with a COPY this is not legal if any of the
users is a SUBREG_TO_REG that asserts the upper bits of the result are
zero.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 83661.Jan 9 2017, 11:42 AM
MatzeB retitled this revision from to PeepholeOptimizer: Do not replace SubregToReg(bitcast like).
MatzeB updated this object.
MatzeB added reviewers: qcolombet, mkuper.
MatzeB set the repository for this revision to rL LLVM.
MatzeB added a subscriber: llvm-commits.
qcolombet accepted this revision.Jan 9 2017, 12:56 PM
qcolombet edited edge metadata.

Hi Matthias,

That's sad that bit casts have side effects, but I agree that it seems to be the best fix. As a side question, are there anything else that check for isBitcast in other optimizations and that may have similar issues?

Anyhow, LGTM.

Cheers,
-Quentin

This revision is now accepted and ready to land.Jan 9 2017, 12:56 PM
MatzeB added a comment.Jan 9 2017, 1:26 PM

Hi Matthias,

That's sad that bit casts have side effects, but I agree that it seems to be the best fix. As a side question, are there anything else that check for isBitcast in other optimizations and that may have similar issues?

Anyhow, LGTM.

Cheers,
-Quentin

That's the only user of MachineInstr::isBitcast(). Of course I do not know if we aren't doing replacements somewhere else that are possibly invalid because they violate the expectations of a SUBREG_TO_REG users (I would describe it as SUBREG_TO_REG breaking referential transparency that we would expect in MachineSSA...)

This revision was automatically updated to reflect the committed changes.