[PATCH] D30537: [DAGCombiner] allow transforming (select Cond, C +/- 1, C) to (add(ext Cond), C)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 2 07:47:15 PST 2017


spatel created this revision.
Herald added subscribers: nemanjai, mcrosier, aemerson.

select Cond, C +/- 1, C --> add(ext Cond), C -- with a target hook.

This is part of the ongoing process to obsolete https://reviews.llvm.org/D24480.

PowerPC is an obvious winner for this kind of transform because it has fast and complete bit-twiddling abilities but generally lousy conditional execution perf (although this might have changed in recent implementations).

x86 also sees some wins, but the effect is limited because these transforms already mostly exist in its target-specific combineSelectOfTwoConstants(). The fact that we see any x86 changes just shows that that code is a mess of special-case holes. We may be able to remove some of that logic if this goes in.

My guess is that other targets will want to enable this hook for most cases. The likely follow-ups would be to add value type and/or the constants themselves as parameters for the hook. As the tests in select_const.ll show, we can transform any select-of-constants to math/logic, but the general transform for any 2 constants needs one more instruction (multiply or 'and').

ARM is one target that I think may not want this for most cases. I see infinite loops there because it wants to use selects to enable conditionally executed instructions.


https://reviews.llvm.org/D30537

Files:
  include/llvm/Target/TargetLowering.h
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  lib/Target/PowerPC/PPCISelLowering.h
  lib/Target/X86/X86ISelLowering.h
  test/CodeGen/PowerPC/crbits.ll
  test/CodeGen/PowerPC/select_const.ll
  test/CodeGen/X86/avx512-insert-extract.ll
  test/CodeGen/X86/avx512-select.ll
  test/CodeGen/X86/select_const.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30537.90333.patch
Type: text/x-patch
Size: 13298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170302/7dc950af/attachment.bin>


More information about the llvm-commits mailing list