This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix a bug when optimizing conditional branch in PPCPreEmitPeephole pass
ClosedPublic

Authored by wmi on Dec 21 2018, 5:25 PM.

Details

Summary

PPCPreEmitPeephole will convert a BC to B when the conditional branch is based on a constant CR by CRSET or CRUNSET. This is added in https://reviews.llvm.org/rL343100.

When the conditional branch is known to be always taken, all branches will be removed and a new unconditional branch will be inserted. However, when SeenUse is false the original patch will not remove the branches, but still insert the new unconditional branch and update the successors, and create inconsistent IR. Compiling the synthetic testcase included can show the problem we run into.

It seems to me removing the patches should not depend on the value of SeenUse so I guess it is an oversight. The patch simply removes the SeenUse condition when adding branches into InstrsToErase set.

Diff Detail

Repository
rL LLVM

Event Timeline

wmi created this revision.Dec 21 2018, 5:25 PM
inouehrs accepted this revision.Dec 24 2018, 11:53 PM

LGTM.
Thank you for finding the problem. I do not remember my intention on checking SeenUse here.

This revision is now accepted and ready to land.Dec 24 2018, 11:53 PM
This revision was automatically updated to reflect the committed changes.