8 Commits

Author SHA1 Message Date
Sanjay Patel
df01cb5e33 [DAGCombiner] fold add/sub with bool operand based on target's boolean contents
I noticed that we are missing this canonicalization in IR:
rL352515
...and then realized that we don't get this right in SDAG either,
so this has to be fixed first regardless of what we choose to do in IR.

The existing fold was limited to scalars and using the wrong predicate
to guard the transform. We have a boolean contents TLI query that can
be used to decide which direction to fold.

This may eventually lead back to the problems/question in:
https://bugs.llvm.org/show_bug.cgi?id=40486
...but it makes no difference to that yet.

Differential Revision: https://reviews.llvm.org/D57401


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353433 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-07 17:43:34 +00:00
Sanjay Patel
648b708c20 [DAGCombiner] transform sub-of-shifted-signbit to add
This is exchanging a sub-of-1 with add-of-minus-1:
https://rise4fun.com/Alive/plKAH

This is another step towards improving select-of-constants codegen (see D48970).

x86 is the motivating target, and those diffs all appear to be wins. PPC and AArch64 look neutral.
I've limited this to early combining (!LegalOperations) in case a target wants to reverse it, but
I think canonicalizing to 'add' is more likely to produce further transforms because we have more
folds for 'add'.

Differential Revision: https://reviews.llvm.org/D49924


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338317 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-30 22:21:37 +00:00
Sanjay Patel
c9159350ae [AArch64, PowerPC, x86] add more signbit math tests; NFC
The tests with a constant sub operand were added with rL338143,
but the potential transform doesn't have that requirement, so
adding more tests with variable operands.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338150 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-27 18:31:21 +00:00
Sanjay Patel
fac43a3123 [AArch64, PowerPC, x86] add more signbit math tests; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338143 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-27 18:12:29 +00:00
Sanjay Patel
125191a9e0 [DAGCombiner] fold 'not' with signbit math
This is a follow-up suggested in D48970. 

Alive proofs:
https://rise4fun.com/Alive/sII

We can eliminate an instruction in the usual select-of-constants 
to bit hack transform by adjusting the add/sub with constant.
This is always a win. 

There are more transforms that are likely wins, but they may need 
target hooks in case some targets do not benefit. 

This is another step towards making up for canonicalizing to 
select-of-constants in rL331486.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338132 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-27 16:42:55 +00:00
Sanjay Patel
67980f703b [PowerPC] add more tests for signbit math; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338130 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-27 16:22:18 +00:00
Sanjay Patel
08378e6ecf [DAGCombiner] extend(ifpositive(X)) -> shift-right (not X)
This is almost the same as an existing IR canonicalization in instcombine, 
so I'm assuming this is a good early generic DAG combine too.

The motivation comes from reduced bit-hacking for select-of-constants in IR 
after rL331486. We want to restore that functionality in the DAG as noted in
the commit comments for that change and the llvm-dev discussion here:
http://lists.llvm.org/pipermail/llvm-dev/2018-July/124433.html

The PPC and AArch tests show that those targets are already doing something 
similar. x86 will be neutral in the minimal case and generally better when 
this pattern is extended with other ops as shown in the signbit-shift.ll tests.

Note the asymmetry: we don't include the (extend (ifneg X)) transform because 
it already exists in SimplifySelectCC(), and that is verified in the later 
unchanged tests in the signbit-shift.ll files. Without the 'not' op, the 
general transform to use a shift is always a win because that's a single 
instruction.

Alive proofs:
https://rise4fun.com/Alive/ysli

Name: if pos, get -1
  %c = icmp sgt i16 %x, -1
  %r = sext i1 %c to i16
  =>
  %n = xor i16 %x, -1
  %r = ashr i16 %n, 15

Name: if pos, get 1
  %c = icmp sgt i16 %x, -1
  %r = zext i1 %c to i16
  =>
  %n = xor i16 %x, -1
  %r = lshr i16 %n, 15

Differential Revision: https://reviews.llvm.org/D48970



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337130 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-15 16:27:07 +00:00
Sanjay Patel
b06fd49497 [AArch64, PowerPC, x86] add tests for signbit bit hacks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336348 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-05 13:16:46 +00:00