Matt Arsenault
73925ef8b0
ValueTracking: Delete body of isKnownNeverInfinity
...
computeKnownFPClass should now handle infinity checks equally as
well as what this could do before so delete the redundant code.
2023-05-18 08:04:37 +01:00
Matt Arsenault
dd61b63b5c
ValueTracking: Handle sign bit for fptrunc in computeKnownFPClass
2023-05-17 23:40:06 +01:00
Matt Arsenault
6666969a08
ValueTracking: Implement computeKnownFPClass for various rounding intrinsics
2023-05-17 23:40:05 +01:00
Nikita Popov
9b7616856c
[ValueTracking] Fix i1 abs range (PR62760)
...
For i1 operations, we may end up returning an empty range instead
of a full one. Make sure to use the getNonEmpty constructor.
Fixes https://github.com/llvm/llvm-project/issues/62760 .
2023-05-17 12:31:13 +02:00
Noah Goldstein
124547eae8
[ValueTracking] Use KnownBits::sdiv for sdiv opcode in computeKnownBits
...
We now of an implementation of `KnownBits::sdiv` so we can implement
this case.
Differential Revision: https://reviews.llvm.org/D150096
2023-05-16 18:58:12 -05:00
Noah Goldstein
99795afb28
[ValueTracking] Pass exact flag to KnownBits::udiv in computeKnownBits
...
This information was previously missing but we can use it for
determining the low-bits.
Differential Revision: https://reviews.llvm.org/D150095
2023-05-16 18:58:12 -05:00
Noah Goldstein
774ecc20e1
[ValueTracking] deduce X * Y != 0 if LowestKnownBit(X) * LowestKnownBit(Y) != 0
...
For `X * Y`, if there exists a subset of `X` and subset of `Y` s.t `sX * sY != 0`,
then `X * Y != 0`.
- See first proof: https://alive2.llvm.org/ce/z/28C9CG
- NB: This is why the previous Odd case works.
In knownbits we could exhaustively hunt for such a subset, but
`LSB(X)` and `LSB(Y)` actually works. If `LSB(X) * LSB(Y) != 0`, then
`X * Y != 0`
- See proof: https://alive2.llvm.org/ce/z/p5wWid
In `isKnownNonZero` we can use this as if the `LowestKnownOne(X) *
LowestKnownOne(Y) != 0`, then `X * Y != 0`, and we don't need to try
and other subsets.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D150425
2023-05-16 18:58:12 -05:00
Matt Arsenault
86d0b524f3
ValueTracking: Expand signature of isKnownNeverInfinity/NaN
...
This is in preparation for replacing the implementation
with a wrapper around computeKnownFPClass.
2023-05-16 20:42:58 +01:00
Matt Arsenault
0ee2245ab2
ValueTracking: Restore ordered negative handling for frem
...
In D148674, the negative condition was weakened to only
checking isKnownNever(fcNegative), instead of cannotBeOrderedLessThanZero().
This avoids a regression when CannotBeOrderedLessThanZero is
replaced with computeKnownFPClass.
2023-05-16 14:38:39 +01:00
Matt Arsenault
c9f88e5bf0
ValueTracking: fadd/fsub +0 cannot return -0
...
Copied from CannotBeNegativeZero and extended to cover fsub.
2023-05-16 14:33:34 +01:00
Matt Arsenault
fe5786d416
ValueTracking: Implement computeKnownFPClass for sqrt
...
Could be slightly smarter in cases that are probably uninteresting.
2023-05-16 12:41:43 +01:00
Jay Foad
d8229e2f14
[KnownBits] Define and use intersectWith and unionWith
...
Define intersectWith and unionWith as two complementary ways of
combining KnownBits. The names are chosen for consistency with
ConstantRange.
Deprecate commonBits as a synonym for intersectWith.
Differential Revision: https://reviews.llvm.org/D150443
2023-05-16 09:23:51 +01:00
Jay Foad
71ac47f391
[KnownBits] Make use of KnownBits.isUnknown. NFC.
2023-05-16 09:19:55 +01:00
Piotr Sobczak
7322d35476
[ValueTracking] Fix computeKnownFPClass with canonicalize
...
Update code that assumes llvm.canonicalize only handles scalars,
by adding a call to getScalarType().
This is fine, as the intrinsic is trivially vectorizable.
Introduced in D147870, and uncovered by D148065.
Differential Revision: https://reviews.llvm.org/D150556
2023-05-15 14:50:35 +02:00
luxufan
f470922a29
Revert "Revert "[ValutTracking] Use isGuaranteedNotToBePoison in impliesPoison""
...
This reverts commit 706e8110573c83f140a63b40803d6370c86c1414.
2023-05-10 14:35:55 +08:00
Noah Goldstein
2647547ee4
Re-revert "[ValueTracking] Use knownbits interface for determining if div/rem are safe to speculate"
...
Seems to be causing a bug in CorrelatedValuePropegation. Reverting
while the issue is investigated.
This reverts commit 6c667abf3294d61e4fbe1238e1755c79f7547f1b.
2023-05-09 19:11:21 -05:00
Hans Wennborg
706e811057
Revert "[ValutTracking] Use isGuaranteedNotToBePoison in impliesPoison"
...
This broke two lit tests:
LLVM :: Transforms/LoopSimplify/merge-exits.ll
LLVM :: Transforms/PhaseOrdering/X86/vector-reductions.ll
see comment on the code review.
> Differential Revision: https://reviews.llvm.org/D149934
This reverts commit 2ba4cfd56769ab50c9c6f432f93265d7793bd1f2.
2023-05-09 09:15:18 +02:00
luxufan
2ba4cfd567
[ValutTracking] Use isGuaranteedNotToBePoison in impliesPoison
...
Differential Revision: https://reviews.llvm.org/D149934
2023-05-09 12:39:58 +08:00
Kazu Hirata
061b5ba9aa
[Analysis] Fix a warning
...
This patch fixes:
llvm/lib/Analysis/ValueTracking.cpp:895:12: error: unused variable
'BitWidth' [-Werror,-Wunused-variable]
2023-05-05 09:09:33 -07:00
Max Kazantsev
7fbf72a101
[ValueTracking][NFC] Factor out computeKnownBitsFromCmp
...
Separate the part which is specific for assume intrinsic from the part which only requires an icmp,
so that the latter could be reused for other purposes (e.g. in dominating conditions).
Differential Revision: https://reviews.llvm.org/D149940
Reviewed By: nikic
2023-05-05 17:04:11 +07:00
Max Kazantsev
1d424eead9
[NFC][ValueTracking] Hoist isValidAssumeForContext out of switch
...
There is a lot of copy-paste-ish checks while this can be done once.
Differential Revision: https://reviews.llvm.org/D149939
Reviewed By: nikic
2023-05-05 16:48:40 +07:00
Siyuan Zhu
edcdc81e2b
[ValueTracking] add UGT/UGE and SGT/SGE in isImpliedCondOperands
...
Partially `fix` https://github.com/llvm/llvm-project/issues/62441 .
Extend isImpliedCondOperands() to handle ugt/uge and sgt/sge predicates.
alive2 proof: https://alive2.llvm.org/ce/z/jLFDAv and
https://alive2.llvm.org/ce/z/Z8idUd
Differential Revision: https://reviews.llvm.org/D149510
2023-05-04 16:59:07 +02:00
Matt Arsenault
d3c6c3f63c
ValueTracking: Sign handling for minnum/maxnum
...
If we know one operand is positive for maxnum, or one is negative
for minnum, the result will have the same sign.
2023-05-02 19:10:37 -04:00
Matt Arsenault
9feb7cbe51
ValueTracking: Handle minimum/maximum in computeKnownFPClass
2023-05-02 16:49:46 -04:00
Matt Arsenault
58295cac92
ValueTracking: Implement computeKnownFPClass for minnum/maxnum
2023-05-02 14:23:54 -04:00
Noah Goldstein
6c667abf32
Recommit "[ValueTracking] Use knownbits interface for determining if div/rem are safe to speculate" (2nd Try)
...
Add `poison` checks that where missing.
Reviewed By: nikic
2023-05-01 17:23:58 -05:00
Noah Goldstein
358cdb4489
Revert "[ValueTracking] Use knownbits interface for determining if div/rem are safe to speculate"
...
Appears to be causing out-of-tree test failures. Reverting while the
issue is investigated.
This reverts commit fbc7fcf5ae26fad7db3e7c861fc6447e02b39cf0.
2023-05-01 13:20:09 -05:00
Noah Goldstein
fbc7fcf5ae
[ValueTracking] Use knownbits interface for determining if div/rem are safe to speculate
...
This just replaces the exact constant requirements with known-bits
which can prove better results.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149423
2023-04-30 10:40:46 -05:00
Noah Goldstein
424b10d6cc
[ValueTracking] Slight refactor to avoid unnecessary work; NFC
...
Two changes:
1) Make some cases that conditionally returned unconditional.
2) In cases of `Op0 != 0 || Op1 != 0` its better check `Op1` first
as its more likely to be a constant due to canonicalization (so
faster to get knownbits of).
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149419
2023-04-30 10:06:46 -05:00
Noah Goldstein
5eedfff695
[ValueTracking] Add additional cases for isKnownNonZero(mul X, Y)
...
If either `X` or `Y` is odd and the other is non-zero, the result is
non-zero.
Alive2 Link:
https://alive2.llvm.org/ce/z/9V7-es
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149418
2023-04-30 10:06:46 -05:00
Noah Goldstein
d840391401
[ValueTracking] Add logic for isKnownNonZero(smin/smax X, Y)
...
For `smin` if either `X` or `Y` is negative, the result is non-zero.
For `smax` if either `X` or `Y` is strictly positive, the result is
non-zero.
For both if `X != 0` and `Y != 0` the result is non-zero.
Alive2 Link:
https://alive2.llvm.org/ce/z/7yvbgN
https://alive2.llvm.org/ce/z/zizbvq
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149417
2023-04-30 10:06:46 -05:00
Noah Goldstein
e78c30a10f
[ValueTracking] Add logic for isKnownNonZero(umin X, Y)
...
`(umin X, Y) != 0` -> `X != 0 && Y != 0`
Alive2 Link:
https://alive2.llvm.org/ce/z/AQh67i
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149416
2023-04-30 10:06:46 -05:00
Noah Goldstein
883daa7ac4
[ValueTracking] Add logic for isKnownNonZero(umax X, Y)
...
`(umax X, Y) != 0` -> `X != 0 || Y != 0`
Alive2 Link:
https://alive2.llvm.org/ce/z/_Z9AUT
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149415
2023-04-30 10:06:46 -05:00
Noah Goldstein
167ecdaa2c
[ValueTracking] Add logic for isKnownNonZero(sadd.sat X, Y)
...
The logic here is the same for `add` so reuse the existing helper
`isNonZeroAdd`
Alive2 Link:
https://alive2.llvm.org/ce/z/mhKvC5
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149414
2023-04-30 10:06:46 -05:00
Noah Goldstein
461ded4631
[ValueTracking] Add logic for isKnownNonZero(ssub.sat X, Y)
...
The logic here is the same for normal `(sub X, Y)`, so just reused
`isNonZeroSub`.
Alive2 Link:
https://alive2.llvm.org/ce/z/9kSkMv
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149412
2023-04-30 10:06:45 -05:00
Noah Goldstein
f1dfa4938a
[ValueTracking] Add logic for isKnownNonZero(sshl.sat/ushl.sat X, Y)
...
`(sshl/ushl X, Y) != 0` -> `X != 0`
Alive2 Links
https://alive2.llvm.org/ce/z/4WLM2p
https://alive2.llvm.org/ce/z/BHFng4
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149411
2023-04-30 10:06:45 -05:00
Noah Goldstein
ea5a0d4b90
[ValueTracking] Add logic for isKnownNonZero(ctlz/cttz X)
...
for `cttz` if `X[0]` is non-zero, then the expression is non-zero.
for `ctlz` if `X[SignBit]` is non-zero, then the expression in
non-zero.
Alive2 Links:
cttz (false): https://alive2.llvm.org/ce/z/ySQzbg
cttz (true): https://alive2.llvm.org/ce/z/auiTCJ
ctlz (false): https://alive2.llvm.org/ce/z/yk3sTJ
ctlz (true): https://alive2.llvm.org/ce/z/-JuDty
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149410
2023-04-30 10:06:45 -05:00
Noah Goldstein
c7f7f601f2
[ValueTracking] Handle bitcasts between vec-int-ptr in isKnownNonZero
...
We where missing these cases so something like:
`(bitcast to i32 (or v216 x, <2, 1>))`
would not be found to be non-zero.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149409
2023-04-30 10:06:45 -05:00
Noah Goldstein
a10515454b
[ValueTracking] Pull out logic for detecting if (add X, Y) is non-zero; NFC
...
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149407
2023-04-30 10:06:45 -05:00
Noah Goldstein
786ce4c4c5
[ValueTracking] Pull out logic for detecting if (sub X, Y) is non-zero; NFC
...
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149406
2023-04-30 10:06:45 -05:00
Justin Lebar
6f01cb91d7
Handle select in programUndefinedIfPoison.
...
If both the true and false operands of a `select` are poison, then the `select`
is poison.
Differential Revision: https://reviews.llvm.org/D149427
2023-04-28 09:09:31 -07:00
Noah Goldstein
4cd1b67491
[ValueTracking] Add logic for fshl/fshr(A, B, C) != 0 if A == B && A ! = 0
...
Having `A == B` is quite common for rotate patterns.
Alive2 Links:
- https://alive2.llvm.org/ce/z/mPXi9c
- https://alive2.llvm.org/ce/z/UfDHoI
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149372
2023-04-28 01:57:37 -05:00
Noah Goldstein
d8e9dd33b2
[ValueTracking] Add logic for udiv x,y != 0 if y u<= x
...
Alive2 Link:
https://alive2.llvm.org/ce/z/2DKh46
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149203
2023-04-27 13:48:41 -05:00
ManuelJBrito
d22edb9794
[IR][NFC] Change UndefMaskElem to PoisonMaskElem
...
Following the change in shufflevector semantics,
poison will be used to represent undefined elements in shufflevector masks.
Differential Revision: https://reviews.llvm.org/D149256
2023-04-27 18:01:54 +01:00
Noah Goldstein
75b48b4077
[ValueTracking] Add logic for add nuw x,y != 0 -> x != 0 || y != 0
...
Alive2 Link:
https://alive2.llvm.org/ce/z/TKpqxc
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149204
2023-04-26 23:48:20 -05:00
Noah Goldstein
9b3c865d32
[ValueTracking] Add logic for (sub x, y) != 0 if we know KnownX != KnownY
...
Alive2 Link:
https://alive2.llvm.org/ce/z/TAFcjF
Differential Revision: https://reviews.llvm.org/D149202
2023-04-26 23:48:17 -05:00
Serguei Katkov
faf8407aec
[InstSimplify] Extend handlng of fp min/max.
...
Add support the cases like
m(m(X,Y),m'(X,Y)) => m(X,Y)
where m is one of maxnum, minnum, maximum, minimum and
m' is m or inverse of m.
alive2 correctness check:
maxnum(maxnum,maxnum) https://alive2.llvm.org/ce/z/kSyAzo
maxnum(maxnum,minnum) https://alive2.llvm.org/ce/z/Vra8j2
minnum(minnum,minnum) https://alive2.llvm.org/ce/z/B6h-hW
minnum(minnum,maxnum) https://alive2.llvm.org/ce/z/rG2u_b
maximum(maximum,maximum) https://alive2.llvm.org/ce/z/N2nevY
maximum(maximum,minimum) https://alive2.llvm.org/ce/z/23RFcP
minimum(minimum,minimum) https://alive2.llvm.org/ce/z/spHZ-U
minimum(minimum,maximum) https://alive2.llvm.org/ce/z/Aa-VE8
Reviewed By: dantrushin, RKSimon
Differential Revision: https://reviews.llvm.org/D147137
2023-04-27 10:45:27 +07:00
luxufan
b12a2fc4e8
[ValueTracking] Guaranteed not to be undef if has dereferenceable attribute
...
As LangRef says, "dereferenceable<n> implies noundef".
`isGuaranteedNotToBeUndefOrPoison` should return true if the parameter
has dereferenceable attribute.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149035
2023-04-27 11:05:49 +08:00
Matt Arsenault
de7bfec885
ValueTracking: Handle frem in computeKnownFPClass
...
I barely understand what this does, but try to
handle the last case required to delete cannotBeOrderedLessThanZeroImpl.
Also improve by following fdiv handling for nans and identical operand case.
2023-04-26 06:22:30 -04:00
Matt Arsenault
be8aafa1e2
ValueTracking: fdiv sign handling in computeKnownFPClass
...
Copy what cannotBeOrderedLessThanZeroImpl checks for fdiv.
2023-04-26 06:22:30 -04:00