This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Adjust ifcvt heuristic for the diamond ifcvt case
ClosedPublic

Authored by john.brawn on Jul 3 2017, 8:52 AM.

Details

Summary

When we have a diamond ifcvt the fallthough block will have a branch at the end of it that disappears when predicated, so discount it from the predication cost.

Diff Detail

Repository
rL LLVM

Event Timeline

john.brawn created this revision.Jul 3 2017, 8:52 AM
samparker added inline comments.Jul 12 2017, 4:02 AM
lib/Target/ARM/ARMBaseInstrInfo.cpp
1885 ↗(On Diff #105087)

Does the '1' represent the single branch instruction that we will not have to execute? Does it not have to be the number of cycles saved?

test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll
98 ↗(On Diff #105087)

why does this patch affect targets with a branch predictor?

john.brawn added inline comments.Jul 12 2017, 4:57 AM
lib/Target/ARM/ARMBaseInstrInfo.cpp
1885 ↗(On Diff #105087)

IfConversion sets the cost of an instruction to be 1 + (latency-1) if latency > 1, but looking at the various sched models latency of branches is either 0 or 1 as a branch doesn't produce any result. Also getting the latency of an instruction requires having a TargetSchedModel which isn't available here, so I'd have to plumb it in from IfConversion.

test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll
98 ↗(On Diff #105087)

It doesn't, I've adjusted the function (see the extra store in if.then below) to make sure we see a difference between bp and nobp (because with the new heuristic both produced the same code for the current version of this function).

samparker accepted this revision.Jul 12 2017, 5:11 AM
samparker added inline comments.
lib/Target/ARM/ARMBaseInstrInfo.cpp
1885 ↗(On Diff #105087)

ok, sounds like a reasonable estimation then.

test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll
98 ↗(On Diff #105087)

ah! sorry, missed that.

This revision is now accepted and ready to land.Jul 12 2017, 5:11 AM
This revision was automatically updated to reflect the committed changes.