Commit Graph

1317 Commits

Author SHA1 Message Date
Nikita Popov
2bc7d02312 Revert "[InstSimplify] Make simplifyWithOpReplaced() recursive (PR63104)"
This is very likely the cause of a stage 2 failure in
Transforms/LoopVectorize/check-prof-info.ll. Revert until I can
investigate this.

This reverts commit 3d199d086e.
2023-07-14 18:33:39 +02:00
Nikita Popov
3d199d086e [InstSimplify] Make simplifyWithOpReplaced() recursive (PR63104)
Support replacement of operands not only in the immediate
instruction, but also instructions it uses.

To the most part, this extension is straightforward, but there are
two bits worth highlighting:

First, we can now no longer assume that if the Op is a vector, the
instruction also returns a vector. If Op is a vector and the
instruction returns a scalar, we should consider it as a cross-lane
operation.

Second, for the x ^ x special case, we can no longer assume that
the operand is RepOp, as we might have a replacement higher up the
instruction chain.

There is one optimization regression, but it is in a fuzzer-generated
test case.

Fixes https://github.com/llvm/llvm-project/issues/63104.
2023-07-14 16:33:40 +02:00
Nikita Popov
91b84811ab [InstSimplify] Add tests for recursive simplify with op replaced (NFC) 2023-07-14 16:06:34 +02:00
Nikita Popov
edb2fc6dab [llvm] Remove explicit -opaque-pointers flag from tests (NFC)
Opaque pointers mode is enabled by default, no need to explicitly
enable it.
2023-07-12 14:35:55 +02:00
Peixin Qiao
31dda3913f [InstCombine] Precommit a test
This patch precommits a test for:
https://reviews.llvm.org/D148420

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D150069
2023-07-12 18:44:36 +08:00
Matt Arsenault
db58a9c03f InstSimplify: Update another cannotBeOrderedLessThanZero use
Pass all the optional arguments to enable assumes.
2023-07-07 08:15:09 -04:00
Matt Arsenault
39f2fce0fa ValueTracking: Update another cannotBeOrderedLessThanZero use 2023-07-07 07:34:33 -04:00
Matt Arsenault
708fa7d926 ValueTracking: Update a use of cannotBeOrderedLessThanZero
Makes assumes work.
2023-07-07 07:33:48 -04:00
Nikita Popov
6c7fd723c4 [InstSimplify] Fold gep inbounds undef to undef instead of poison
With the semantics change from D154051, it is no longer valid to
fold gep inbounds undef to poison (unless we know the index is
non-zero). Fold it to undef instead.

Differential Revision: https://reviews.llvm.org/D154215
2023-07-06 14:59:22 +02:00
Anshil Gandhi
e578b3be24 [InstSimplify] Fold all global variables with initializers
Allow computing size of interposable or externally initializable global variables.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D152145
2023-07-03 15:11:41 -06:00
Hanbum Park
46a5745017 [InstSimplify] Fold icmp of allocas based on offset difference
Strengthen the fold for icmps of non-overlapping storage, by
working on the difference of offsets, rather than considering
both offsets independently. In particular, this allows handling
comparisons of pointers to the end of equal-sized allocations.

Proofs: https://alive2.llvm.org/ce/z/Po2nL4

Differential Revision: https://reviews.llvm.org/D153752
2023-06-29 09:16:26 +02:00
Fraser Cormack
55372309a4 [InstSimplify] Fix a scalable-vector crash
D143505 fixed/simplified folding of operations with SNaN operands. In
doing so it introduced a crash when handling scalable vector types,
wherein the scalable-vector ConstantVector was cast to a ConstantFP.

Since we know by that point in the code that if we've found a NaN, we're
dealing with a scalable-vector splat (as there are no other kinds of
scalable-vector constant for which that holds), we can grab the splatted
value and re-use the existing code, which will automatically splat the
new NaN back to a scalable vector for us.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D153566
2023-06-28 17:07:10 +01:00
Matt Arsenault
13cf479dd1 ValueTracking: Use new version of cannotBeOrderedLessThanZero
Pass all arguments so now assumes work.
2023-06-23 19:26:30 -04:00
Nikita Popov
f6a8775c5d [InstSimplify] Fold icmp of uadd.sat/usub.sat (PR63381)
Fold uadd.sat(X, Y) uge X and usub.sat(X, Y) ule X to true.

Proof: https://alive2.llvm.org/ce/z/596m9X

Fixes https://github.com/llvm/llvm-project/issues/63381.
2023-06-19 11:49:38 +02:00
Nikita Popov
4511d3c33c [InstSimplify] Add test for icmp of uadd.sat/usub.sat (NFC) 2023-06-19 11:49:38 +02:00
Arthur Eubanks
f4f826bcd4 Revert "Revert "ValueTracking: Fix nan result handling for fmul""
This reverts commit 464dcab8a6.

Going to fix forward size regression instead due to more dependent patches needing to be reverted otherwise.
2023-06-16 13:53:32 -07:00
Arthur Eubanks
464dcab8a6 Revert "ValueTracking: Fix nan result handling for fmul"
This reverts commit a632ca4b00.

Dependent commit to be reverted
2023-06-16 11:24:28 -07:00
Matt Arsenault
a632ca4b00 ValueTracking: Fix nan result handling for fmul
This was mishandling maybe 0 * inf.

Fixes issue #63316
2023-06-15 09:35:12 -04:00
Matt Arsenault
9348d83f62 ValueTracking: Add some baseline tests for issue #63316 2023-06-15 09:35:12 -04:00
Alan Zhao
3d5cf0df4f Revert "[InstSimplify] Fold all global variables with initializers"
This reverts commit 17b7df3dae.

Reason: causes chrome builds to crash: https://crbug.com/1454861
2023-06-14 14:10:31 -07:00
Anshil Gandhi
17b7df3dae [InstSimplify] Fold all global variables with initializers
Allow computing size of interposable or externally initializable global variables.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D152145
2023-06-13 15:15:19 -06:00
Joshua Cao
cb9f1aadda [ValueTracking] Implied conditions for lshr
`V1 >> V2 u<= V1` for any V1, V2

This works for lshr and any div's that are changed to lshr's

This fixes issues in clang and rustc:
https://github.com/llvm/llvm-project/issues/62441
https://github.com/rust-lang/rust/issues/110971

Reviewed By: goldstein.w.n

Differential Revision: https://reviews.llvm.org/D151541
2023-06-06 21:06:22 -07:00
Joshua Cao
f23b4faaff [InstSimplify] Add tests for shl implied conditions 2023-06-06 21:06:22 -07:00
luxufan
1ac99bc452 [InstSimplify] Simplify select i1 ConstExpr, i1 true, i1 false to ConstExpr
`select i1 non-const, i1 true, i1 false` has been optimized to
`non-const`. There is no reason that we can not optimize `select i1
ConstExpr, i1 true, i1 false` to `ConstExpr`.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D151631
2023-06-03 15:09:00 +08:00
Noah Goldstein
2622b2f409 [ValueTracking] Use select condition to help determine if select is non-zero
In `select c, x, y` the condition `c` dominates the resulting `x` or
`y` chosen by the `select`. This adds logic to `isKnownNonZero` to try
and use the `icmp` for the `c` condition to see if it implies the
select `x` or `y` are known non-zero.

For example in:
    ```
    %c = icmp ugt i8 %x, %C
    %r = select i1 %c, i8 %x, i8 %y
    ```
    The true arm of select `%x` is non-zero (when "returned" by the
    `select`) because `%c` being true implies `%x` is non-zero.

Alive2 Links (with `x {pred} C`):
    - EQ  iff `C != 0`:
        - https://alive2.llvm.org/ce/z/umLabn
    - NE  iff `C == 0`:
        - https://alive2.llvm.org/ce/z/DQvy8Y
    - UGT [always]:
        - https://alive2.llvm.org/ce/z/HBkjgQ
    - UGE iff `C != 0`:
        - https://alive2.llvm.org/ce/z/LDNifB
    - SGT iff `C s>= 0`:
        - https://alive2.llvm.org/ce/z/QzWDj3
    - SGE iff `C s> 0`:
        - https://alive2.llvm.org/ce/z/rR4g3D
    - SLT iff `C s<= 0`:
        - https://alive2.llvm.org/ce/z/uysayx
    - SLE iff `C s< 0`:
        - https://alive2.llvm.org/ce/z/2jYc7e

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D147900
2023-05-23 13:52:40 -05:00
Matt Arsenault
4023ca1292 Reapply "InstSimplify: Pass AssumptionCache to isKnownNeverInfinity"
This reverts commit 481191b0a8.
2023-05-23 08:48:25 +01:00
Matt Arsenault
c21f1feed3 ValueTracking: Drop rounding mode check for constrained_sqrt in CannotBeNegativeZero
The only value that can produce -0 is exactly -0, no rounding is involved. If the
denormal mode has flushed denormal inputs, a negative value could produce -0.
The constrained intrinsics do not track the denormal mode, and this is just
generally broken in the current set of FP predicates. The move to computeKnownFPClass
will address some of these issues.
2023-05-22 10:49:10 +01:00
Matt Arsenault
15bcb9a697 ValueTracking: Add some regression tests for fabs handling in computeKnownFPClass 2023-05-22 10:33:10 +01:00
Matt Arsenault
6f0344f76a ValueTracking: Add baseline tests for some assume handling 2023-05-19 22:44:12 +01:00
Alina Sbirlea
481191b0a8 Revert "InstSimplify: Pass AssumptionCache to isKnownNeverInfinity"
This reverts commit 0012b94a4e.
Reverting due to test failures introduced by 73925ef8b0
Updated floating-point-compare.ll to keep the assume declaration.
2023-05-18 23:31:50 -07:00
Matt Arsenault
c9bbc64eeb InstSimplify: Pass AssumptionCache through fcmp ord/uno simplification 2023-05-19 00:48:04 +01:00
Matt Arsenault
84e64d9bee InstSimplify: Pass AssumptionCache to isKnownNeverNaN queries 2023-05-19 00:48:03 +01:00
Matt Arsenault
b42ee1d6c3 InstSimplify: Pass AssumptionCache through more isKnownNeverNaN queries 2023-05-19 00:48:03 +01:00
Matt Arsenault
0012b94a4e InstSimplify: Pass AssumptionCache to isKnownNeverInfinity
Makes these cases work with assumes.
2023-05-19 00:48:03 +01:00
Matt Arsenault
07365f4a40 InstSimplify: Combine computeKnownFPClass calls and pass AssumptionCache 2023-05-18 23:29:47 +01:00
Tobias Hieta
f84bac329b [NFC][Py Reformat] Reformat lit.local.cfg python files in llvm
This is a follow-up to b71edfaa4e
since I forgot the lit.local.cfg files in that one.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: barannikov88, kwk

Differential Revision: https://reviews.llvm.org/D150762
2023-05-17 17:03:15 +02:00
Zhongyunde
cd87fe0c8b [Instsimplfy] X == Y ? 0 : X ^ Y --> X ^ Y
Alive2: https://alive2.llvm.org/ce/z/cykffE
Fixes: https://github.com/llvm/llvm-project/issues/62753

Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D150750
2023-05-17 18:36:39 +08: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
Nikita Popov
7d9f03f4d8 [InstSimplify] Add tests for PR62760 (NFC) 2023-05-17 12:31:13 +02:00
khei4
0d67d9aeda [ConstantFolding] fold integer bitwidth is greater than 63, and not multiple of 8 variables
Differential Revision: https://reviews.llvm.org/D150422
2023-05-17 11:09:18 +09:00
Jun Zhang
a47b56f4ef [Instsimplfy] X == Y ? 0 : X - Y --> X - Y
Alive2: https://alive2.llvm.org/ce/z/rPN1GB
Fixes: https://github.com/llvm/llvm-project/issues/62238

Depends on D150377

Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D150378
2023-05-16 19:15:47 +08:00
Jun Zhang
ba3dbcc779 Add baseline tests for PR62238
Differential Revision: https://reviews.llvm.org/D150377

Signed-off-by: Jun Zhang <jun@junz.org>
2023-05-16 19:15:30 +08: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
Siyuan Zhu
2444fb93e6 [InstSimplify] Test case for icmp imply (NFC)
ugt/uge/sgt/sge test for the extension to isImpliedCondOperands
case from issue 62441 and 61393:
(X >> Z) <=(u) Y ==> X <=(to u) Y and (X > Y +_{nuw} 1) ==> X != Y

Differential Revision: https://reviews.llvm.org/D149512
2023-05-04 16:57:38 +02:00
ManuelJBrito
853d212e32 [InstSimplify] Update to handle new shufflevector semantics
Simplifying poison mask elements yields poison values.

Differential Revision: https://reviews.llvm.org/D149544
2023-05-03 21:31:19 +01:00
Matt Arsenault
bc37be1855 LangRef: Add "dynamic" option to "denormal-fp-math"
This is stricter than the default "ieee", and should probably be the
default. This patch leaves the default alone. I can change this in a
future patch.

There are non-reversible transforms I would like to perform which are
legal under IEEE denormal handling, but illegal with flushing zero
behavior. Namely, conversions between llvm.is.fpclass and fcmp with
zeroes.

Under "ieee" handling, it is legal to translate between
llvm.is.fpclass(x, fcZero) and fcmp x, 0.

Under "preserve-sign" handling, it is legal to translate between
llvm.is.fpclass(x, fcSubnormal|fcZero) and fcmp x, 0.

I would like to compile and distribute some math library functions in
a mode where it's callable from code with and without denormals
enabled, which requires not changing the compares with denormals or
zeroes.

If an IEEE function transforms an llvm.is.fpclass call into an fcmp 0,
it is no longer possible to call the function from code with denormals
enabled, or write an optimization to move the function into a denormal
flushing mode. For the original function, if x was a denormal, the
class would evaluate to false. If the function compiled with denormal
handling was converted to or called from a preserve-sign function, the
fcmp now evaluates to true.

This could also be of use for strictfp handling, where code may be
changing the denormal mode.

Alternative name could be "unknown".

Replaces the old AMDGPU custom inlining logic with more conservative
logic which tries to permit inlining for callees with dynamic handling
and avoids inlining other mismatched modes.
2023-04-29 08:44:59 -04:00
ManuelJBrito
8b56da5e9f [IR] Change shufflevector undef mask to poison
With this patch an undefined mask in a shufflevector will be printed as poison.
This change is done to support the new shufflevector semantics
for undefined mask elements.

Differential Revision: https://reviews.llvm.org/D149210
2023-04-27 14:41:10 +01: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
Zhongyunde
f9478f729e [InstSimplify] with logical ops: (X & Y) == -1 ? X : -1 --> -1
Use simplifySelectWithICmpEq to handle the implied equalities from the icmp-and,
then both of ICMP_NE and ICMP_EQ will be addressed including vector type.
    (X & Y) == -1 ?  X : -1 --> -1 (commuted 2 ways)
    (X & Y) != -1 ? -1 :  X --> -1 (commuted 2 ways)
This is a supplement to the icmp-or scenario on D148986.

Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149229
2023-04-26 15:53:02 +08:00
Zhongyunde
0f28cecf1b [tests] precommit tests for D149229
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149230
2023-04-26 15:50:30 +08:00