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
Matt Arsenault
77e3fea02b
ValueTracking: Improve trunc handling in computeKnownFPClass
2023-04-26 05:20:56 -04:00
Matt Arsenault
2ff52ea4ad
ValueTracking: Handle powi in computeKnownFPClass
...
Extract the handling from cannotBeOrderedLessThanZeroImpl and
avoid the mentioned -0 bug.
2023-04-26 05:20:55 -04:00
Matt Arsenault
8e72219973
ValueTracking: Implement computeKnownFPClass for log
2023-04-26 05:20:55 -04:00
Matt Arsenault
f40d186d4a
ValueTracking: Add ordered negative handling for fmul to computeKnownFPClass
...
Port from the existing handling in cannotBeOrderedLessThanZero
2023-04-24 22:31:20 -04:00
Matt Arsenault
7aeec64215
ValueTracking: Handle fptrunc_round in computeKnownFPClass
2023-04-24 22:31:20 -04:00
Matt Arsenault
a070dbfd14
ValueTracking: Implement computeKnownFPClass for fma/fmuladd
...
Copy handling from CannotBeOrderedLessThanZero
2023-04-24 14:29:35 -04:00
Matt Arsenault
d46f8c6ec9
ValueTracking: Handle exp/exp2 in computeKnownFPClass
2023-04-24 14:25:06 -04:00
Matt Arsenault
b0aa6d76eb
ValueTracking: Fix computeKnownFPClass for fabs
...
The fabs utility functions have the opposite purpose and
probably should not be a general utility.
2023-04-24 14:25:06 -04:00
Matt Arsenault
c55fffecce
ValueTracking: Recognize >=, <= compares with 0 as is.fpclass masks
...
Leave DAZ handling for a future change.
2023-04-21 08:15:04 -04:00
Matt Arsenault
6966859059
ValueTracking: Implement computeKnownFPClass for fpext
2023-04-21 07:02:55 -04:00
Matt Arsenault
83adfc91e8
ValueTracking: uitofp/sitofp cannot return denormal results
2023-04-19 20:11:34 -04:00
Matt Arsenault
02f647f892
ValueTracking: Handle sign bit of constrained sitofp/uitofp
...
This is for parity with CannotBeNegativeZero which is close to
droppable.
2023-04-19 20:11:33 -04:00
Matt Arsenault
f6d79ad9eb
ValueTracking: Implement computeKnownFPClass for fdiv for nan handling
2023-04-19 20:11:33 -04:00
Matt Arsenault
e7bcfea622
ValueTracking: Fix backwards handling of fpclass assumes
...
This was a bit confused because nofpclass expresses the opposite
from what an assume of class expresses. We need to assume
the intersection of assumed classes, which also needs to be inverted
to convert to nofpclass.
2023-04-19 20:11:32 -04:00
Matt Arsenault
dea4f37b7d
ValueTracking: Handle shufflevector in computeKnownFPClass
2023-04-19 08:18:37 -04:00
Matt Arsenault
8e70ed6efd
ValueTracking: Handle insertelement in computeKnownFPClass
2023-04-19 08:18:37 -04:00
Matt Arsenault
0d448783c3
ValueTracking: sitofp cannot return -0
2023-04-19 08:18:37 -04:00
OCHyams
ca10e73b53
[NFC] Rename isPointerOffset to getPointerOffsetFrom and move to Value.h
...
Linking LLVMCore failed when building D148536 with shared libs enabled:
https://lab.llvm.org/buildbot/#/builders/121/builds/29766
Make isPointerOffset a Value method and rename it to getPointerOffsetFrom.
Reviewed By: jmorse
Differential Revision: https://reviews.llvm.org/D148698
2023-04-19 12:22:58 +01:00
Noah Goldstein
e846ec57cb
Recommit "[ValueTracking] Apply the isKnownNonZero techniques in ashr/lshl to shl and vice-versa" (2nd Try)
...
Wasn't related to the bug it was original thought to be causing.
2023-04-18 17:17:57 -05:00
Nikita Popov
294831688f
[ValueTracking] Use SmallPtrSetImpl (NFC)
...
Don't hardcode set size in function signature.
2023-04-18 12:37:15 +02:00
Noah Goldstein
3c4d9cc273
Revert "[ValueTracking] Apply the isKnownNonZero techniques in ashr/lshl to shl and vice-versa"
...
May be related to PR62175
This reverts commit 57590d1dd47bbe9aa4b79a0f93cc3ec62cc5d060.
2023-04-18 01:23:08 -05:00
Noah Goldstein
57590d1dd4
[ValueTracking] Apply the isKnownNonZero techniques in ashr/lshl to shl and vice-versa
...
For all shifts we can apply the same two optimizations.
1) `ShiftOp(KnownVal.One, Max(KnownCnt)) != 0`
-> result is non-zero
2) If already known `Val != 0` and we only shift out zeros (based
on `Max(KnownCnt)`)
-> result is non-zero
The former exists for `shl` and the latter (for constant `Cnt`) exists
for `ashr`/`lshr`.
This patch improves the latter to use `Max(KnownCnt)` instead of
relying on a constant shift `Cnt` and applies both techniques for all
shift ops.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D148404
2023-04-17 22:39:06 -05:00
Nikita Popov
fd63a7d5c8
Revert "ValueTracking: Handle freeze in computeKnownFPClass"
...
This reverts commit 2c8d0048f03d054f13909a26f959ef95b2a0a4de.
This is incorrect: computeKnownFPClass() is only known up to
poison, and freeze poison may have any FP class.
2023-04-17 12:59:23 +02:00
Noah Goldstein
f688d215e5
[ValueTracking] Add shl nsw %val, %cnt != 0 if %val != 0.
...
Alive2 Link: https://alive2.llvm.org/ce/z/mxZLJn
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D147898
2023-04-14 18:23:47 -05:00
Noah Goldstein
684963b86d
[ValueTracking] Use maximum shift count in shl when determining if shl can be zero.
...
Previously only return `shl` non-zero if the shift value was `1`. We
can expand this if we have some bounds on the shift count.
For example:
```
%cnt = and %c, 16 ; Max cnt == 16
%val = or %v, 4 ; val[2] is known one
%shl = shl %val, %cnt ; (val.known.one << cnt.maxval) != 0
```
Differential Revision: https://reviews.llvm.org/D147897
2023-04-14 18:23:45 -05:00
Matt Arsenault
2c8d0048f0
ValueTracking: Handle freeze in computeKnownFPClass
2023-04-14 17:53:41 -04:00