This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Handle inverted conditions when splitting into multiple branches.
ClosedPublic

Authored by gberry on Jan 5 2017, 2:24 PM.

Details

Summary

When conditional branches with complex conditions are split into
multiple branches in SelectionDAGBuilder::FindMergedConditions, also
handle inverted conditions. These may sometimes appear without having
been optimized by InstCombine when CodeGenPrepare decides to sink and
duplicate cmp instructions, causing them to have only one use. This
problem can be increased by e.g. GVNHoist hiding more cmps from
InstCombine by combining equivalent cmps from different blocks.

For example codegen X & !(Y | Z) as:

  jmp_if_X TmpBB
  jmp FBB
TmpBB:
  jmp_if_notY Tmp2BB
  jmp FBB
Tmp2BB:
  jmp_if_notZ TBB
  jmp FBB

Event Timeline

gberry updated this revision to Diff 83306.Jan 5 2017, 2:24 PM
gberry retitled this revision from to [SelectionDAG] Handle inverted conditions when splitting into multiple branches..
gberry updated this object.
gberry added reviewers: bogner, MatzeB, qcolombet.
gberry added subscribers: sebpop, hiraditya, llvm-commits.

The patch seems to be inline with and extending the current functionality of the FindMergedConditions optimization, so it LGTM. However, I'll give others an opportunity to chime in before giving a formal approval.

Did you collect any performance results for AArch64 and/or X86? I looked at the AArch64 binary diffs, but nothing jumped out at me.

I did some performance testing on aarch64 (kryo) and there was a slight improvement overall, though almost all of the differences look to be due to indirect I$ effects.
For x86, the static instruction count improves by .02% over all benchmarks, with no significant static instruction count regressions.

My primary motivation for getting this patch in is to address PR31382 in order to get my change (D27722) to move GVNHoist later in the optimization pipeline re-enabled

The change looks good to me: I will let one of the maintainers of selectionDAG approve the patch.
Thanks for fixing this such that we can close PR31382 and commit again the gvn-hoist patch.

Ping? @bogner would you mind taking a look at this or suggesting someone else that could?

This revision was automatically updated to reflect the committed changes.

Approved by @bogner via email

This commit causes https://llvm.org/bugs/show_bug.cgi?id=31914.
I imagine this is an issue in the PPC back end so I don't mind investigating. I'm just wondering if you have any suggestions as to what the issue might be.