This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSE] Make branches unconditional if the condition is known
AbandonedPublic

Authored by mkazantsev on Apr 25 2017, 4:44 AM.

Details

Summary

If EarlyCSE has proved that branch condition is true/false, it can replace it with unconditional branch to the corresponding block.

Diff Detail

Event Timeline

mkazantsev updated this revision to Diff 96531.Apr 25 2017, 4:46 AM

Added space in the debug message.

EarlyCSE is supposed to preserve the CFG (calls setPreservesCFG, depends on DomTree/MemorySSA etc.), so you can't replace a conditional branch with an unconditional branch. Replacing the value of the condition with "true" or "false" is fine, though.

Why do we want to do this specifically for branches, as opposed to doing it for any instruction where we can prove an operand is constant?

mkazantsev planned changes to this revision.Apr 26 2017, 9:18 PM

Needs rework (or maybe abandoning) since EarlyCSE is not supposed to change the CFG.

mkazantsev abandoned this revision.Apr 28 2017, 4:31 AM

Need a more general solution regarding scope, and also need to avoid breaking CFG. I will do it in a separate patch using another approach later.