This is an archive of the discontinued LLVM Phabricator instance.

change DAG's JumpIsExpensive check for x86 (PR23827)
AbandonedPublic

Authored by spatel on Jun 25 2015, 11:59 AM.

Details

Summary

I think the !isJumpExpensive() optimization in SelectionDAGBuilder is not appropriate for any target given that we're not using any branch predictability information or even asking what the cost of boolean logic ops are relative to branches, but this 1-line patch just disables the transform for x86 to solve PR23827:
https://llvm.org/bugs/show_bug.cgi?id=23827

The proper long-term fix IMO is to make isJumpExpensive() a virtual method rather than a bool so targets can override it to use whatever branch prediction and micro-arch info they have. As noted in PR23827, SimplifyCFG does the opposite transform, and that may be a separate bug.

I've added a command-line override to preserve secondary regression test behavior and to make it easier to measure performance differences going forward. The existing or-branch.ll regression test confirms that we're not splitting the condition logic whereas before it confirmed that we were splitting that logic (creating an extra branch).

Diff Detail

Event Timeline

spatel updated this revision to Diff 28486.Jun 25 2015, 11:59 AM
spatel retitled this revision from to change DAG's JumpIsExpensive check for x86 (PR23827).
spatel updated this object.
spatel edited the test plan for this revision. (Show Details)
spatel added reviewers: hfinkel, chandlerc, nadav.
spatel added a subscriber: Unknown Object (MLST).
chandlerc requested changes to this revision.Jun 26 2015, 1:31 AM
chandlerc edited edge metadata.

This seems really unlikely to be a good change.

Jump instructions are not expensive on x86 in general. They certainly are not more expensive than things like sete! I think we usually want to use more jumps rather than moving things out of condition registers.

I think the bug report you're trying to fix is flat out incorrect and backwards. I've updated it.

This revision now requires changes to proceed.Jun 26 2015, 1:31 AM

Thanks, Chandler.

From: https://llvm.org/bugs/show_bug.cgi?id=23827#c6
"We should not encode some magical meaning to a bitwise-and"

I'd always assumed that a bitwise op caused type promotion of the bool, so it was a legitimate way to tell the compiler to avoid the branch. I've followed up with a message to the dev lists.

spatel abandoned this revision.Jun 30 2015, 11:39 AM

Abandoning. See new patch in D10846 after discussion on the mailing lists and PR23827.