llvm-project/llvm/test/Transforms/CorrelatedValuePropagation
Roman Lebedev 8d487668d0
[CVP] Soften SDiv into a UDiv as long as we know domains of both of the operands.
Yes, if operands are non-positive this comes at the extra cost
of two extra negations. But  a. division is already just
ridiculously costly, two more subtractions can't hurt much :)
and  b. we have better/more analyzes/folds for an unsigned division,
we could end up narrowing it's bitwidth, converting it to lshr, etc.

This is essentially a take two on 0fdcca07ad,
which didn't fix the potential regression i was seeing,
because ValueTracking's computeKnownBits() doesn't make use
of dominating conditions in it's analysis.
While i could teach it that, this seems like the more general fix.

This big hammer actually does catch said potential regression.

Over vanilla test-suite + RawSpeed + darktable
(10M IR instrs, 1M IR BB, 1M X86 ASM instrs), this fires/converts 5 more
(+2%) SDiv's, the total instruction count at the end of middle-end pipeline
is only +6, so out of +10 extra negations, ~half are folded away,
and asm instr count is only +1, so practically speaking all extra
negations are folded away and are therefore free.
Sadly, all these new UDiv's remained, none folded away.
But there are two less basic blocks.

https://rise4fun.com/Alive/VS6

Name: v0
Pre: C0 >= 0 && C1 >= 0
%r = sdiv i8 C0, C1
  =>
%r = udiv i8 C0, C1

Name: v1
Pre: C0 <= 0 && C1 >= 0
%r = sdiv i8 C0, C1
  =>
%t0 = udiv i8 -C0, C1
%r = sub i8 0, %t0

Name: v2
Pre: C0 >= 0 && C1 <= 0
%r = sdiv i8 C0, C1
  =>
%t0 = udiv i8 C0, -C1
%r = sub i8 0, %t0

Name: v3
Pre: C0 <= 0 && C1 <= 0
%r = sdiv i8 C0, C1
  =>
%r = udiv i8 -C0, -C1
2020-07-18 17:59:56 +03:00
..
2010-09-02-Trunc.ll
2010-09-26-MergeConstantRange.ll
add.ll
alloca.ll
and.ll
ashr.ll
basic.ll
conflict.ll
crash.ll
deopt.ll
guards.ll
icmp.ll [LVI][CVP] Handle (x | y) < C style conditions 2020-07-01 20:43:24 +02:00
merge-range-and-undef.ll [ValueLattice] Distinguish between constant ranges with/without undef. 2020-03-31 12:50:20 +01:00
mul.ll [CVP] Deduce no-wrap on `mul` 2019-10-21 08:21:44 +00:00
non-null.ll [CVP] Add another non null test (NFC) 2020-06-20 13:05:42 +02:00
overflow_predicate.ll
overflows.ll [CVP] After proving that @llvm.with.overflow()/@llvm.sat() don't overflow, also try to prove other no-wrap 2019-10-18 19:32:47 +00:00
phi-common-val.ll Infer alignment of unmarked loads in IR/bitcode parsing. 2020-05-14 13:03:50 -07:00
pointer.ll
pr35807.ll
profmd.ll
range.ll Infer alignment of unmarked loads in IR/bitcode parsing. 2020-05-14 13:03:50 -07:00
sdiv.ll [CVP] Soften SDiv into a UDiv as long as we know domains of both of the operands. 2020-07-18 17:59:56 +03:00
select.ll [JT][CVP] Regenerate test checks, again 2019-11-01 22:27:48 +01:00
sext.ll
shl.ll [CVP] No-wrap deduction for `shl` 2019-10-21 21:31:19 +00:00
srem.ll
sub.ll [ValueLattice] Merging unknown with empty CR is unknown. 2020-04-25 13:43:34 +01:00
udiv.ll [llvm] Fix broken cases of 'CHECK[^:]*$' in tests 2020-01-28 09:52:59 -07:00
urem.ll [llvm] Fix broken cases of 'CHECK[^:]*$' in tests 2020-01-28 09:52:59 -07:00