Commit Graph

1176 Commits

Author SHA1 Message Date
Roman Lebedev
5b4b842ffb [NFC] Port all InstSimplify tests to -passes= syntax 2022-12-08 02:38:45 +03:00
Matt Arsenault
7f4429c0e4 ValueTracking: Teach CannotBeOrderedLessThanZero about copysign 2022-12-06 09:01:39 -05:00
Matt Arsenault
dbca874faa ValueTracking: Teach CannotBeOrderedLessThanZero about trivial ops
Handle canonicalize and arithmetic.fence
2022-12-05 08:39:07 -05:00
Matt Arsenault
db0f258479 ValueTracking: Teach isKnownNeverNaN about arithmetic_fence 2022-12-05 08:39:07 -05:00
Matt Arsenault
dac496fb1f ValueTracking: Teach isKnownNeverInfinity about arithmetic.fence 2022-12-05 08:39:07 -05:00
Sanjay Patel
47f5da47f5 [InstSimplify] (X && Y) ? X : Y --> Y
Similar to the recent fold that was added for 'or' in D138815:
https://alive2.llvm.org/ce/z/PBapTJ
2022-11-30 15:44:48 -05:00
Sanjay Patel
d422f7e494 [InstSimplify] add tests for select with common 'and' ops; NFC 2022-11-30 15:44:48 -05:00
chenglin.bi
f297332749 [InstSimplify] Fold (X || Y) ? X : Y --> X
(X || Y) ? X : Y --> X
https://alive2.llvm.org/ce/z/oRQJee

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D138815
2022-11-30 10:14:17 +08:00
chenglin.bi
1fd4d91fa6 [InstSimplify] Fold !(X || Y) && X --> false
!(X || Y) && X --> false
https://alive2.llvm.org/ce/z/693Jgv

Fix: [56654](https://github.com/llvm/llvm-project/issues/56654)
Fix: [56780](https://github.com/llvm/llvm-project/issues/56780)

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D138853
2022-11-29 22:45:24 +08:00
chenglin.bi
0752fb57e4 [InstSimplify] Fold (X || Y) ? false : X --> false
(X || Y) ? false : X --> false
https://alive2.llvm.org/ce/z/y93yUm

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D138700
2022-11-29 22:08:50 +08:00
chenglin.bi
0869a96ca9 [InstSimplify] add precommit test for pattern !(X || Y) && X --> false; NFC 2022-11-29 04:07:43 +08:00
chenglin.bi
52dd5b6e95 [InstSimplify] add precommit test for pattern (X || Y) ? false : X -> false; NFC 2022-11-29 03:47:34 +08:00
chenglin.bi
617be4f37b [InstSimplify] Add precommit tests for select+or patterns; NFC 2022-11-28 22:58:39 +08:00
chenglin.bi
b400dde473 [InstSimplify] Use dominate condtion to simplify instructions
Fix #56795

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D138542
2022-11-26 21:41:41 +08:00
chenglin.bi
79fd94e9e7 [InstSimplify] Add precommit test for D138542; NFC 2022-11-24 09:04:33 +08:00
Matt Arsenault
841a0edd03 ConstantFolding: Constant fold some canonicalizes
+/-0 is obviously foldable. Other non-special, non-subnormal
values are also probably OK. For denormal values, check
the calling function's denormal mode. For now, don't fold
denormals to the input for IEEE mode because as far as I know
the langref is still pretending LLVM's float isn't IEEE.

Also folds undef to 0, although NaN may make more sense. Skips
folding nans and infinities, although it should be OK to fold those
in a future change.
2022-11-18 10:35:19 -08:00
Matt Arsenault
d2bbe5a5ff InstSimplify: Add baseline tests for canonicalize 2022-11-18 08:53:50 -08:00
Matt Arsenault
af7e80b7cb ValueTracking: Look through copysign in isKnownNeverInfinity 2022-11-17 08:52:09 -08:00
Matt Arsenault
29e4363dda ValueTracking: Look through fneg in isKnownNeverNaN 2022-11-17 08:35:49 -08:00
Matt Arsenault
ba1669c81f ValueTracking: Look through fabs and fneg in isKnownNeverInfinity 2022-11-17 00:06:15 -08:00
Matt Arsenault
d24fe812ec ValueTracking: Look through canonicalize in isKnownNeverInfinity 2022-11-17 00:06:15 -08:00
Matt Arsenault
fde4ef1973 InstSimplify: Fold arithmetic_fence as idempotent 2022-11-15 22:29:34 -08:00
Sanjay Patel
0a37290dc8 [InstSimplify] restrict logic fold with partial undef vector
https://alive2.llvm.org/ce/z/4ncsnX

Fixes #58977
2022-11-14 12:09:23 -05:00
Sanjay Patel
c2c48f0c96 [InstSimplify] add test for fsub with inf operand; NFC
Verify that constant negation works with a partial undef vector.
Also, remove a bogus TODO comment on a related test.
2022-11-11 09:17:20 -05:00
Sanjay Patel
21f1b2da95 [InstSimplify] fold fsub nnan with Inf operand
Similar to fbc2c8f2fb, but if we have a non-canonical
fsub with constant operand 1, then flip the sign of the
Infinity:
https://alive2.llvm.org/ce/z/vKWfhW

If Infinity is operand 0, then the sign remains:
https://alive2.llvm.org/ce/z/73d97C
2022-11-11 08:42:44 -05:00
Sanjay Patel
fbc2c8f2fb [InstSimplify] fold X +nnan Inf
If we exclude NaN (and therefore the opposite Inf),
anything plus Inf is Inf:
https://alive2.llvm.org/ce/z/og3dj9
2022-11-10 17:13:26 -05:00
Sanjay Patel
58167f67dc [InstSimplify] add tests for fadd/fsub with inf constant operand; NFC 2022-11-10 17:13:26 -05:00
Bjorn Pettersson
ac696ac453 Use opt -passes=<name> instead of opt -name
Updated the RUN line in several test cases to use the new PM syntax
  opt -passes=<pipeline>
instead of the deprecated syntax
  opt -pass1 -pass2
2022-11-08 12:15:42 +01:00
Matt Arsenault
7dd27a75a2 InstSimplify: Fold fdiv nnan ninf x, 0 -> poison
https://alive2.llvm.org/ce/z/JxX5in
2022-11-07 08:43:22 -08:00
Matt Arsenault
1ce5f93d03 InstSimplify: Add new baseline tests for fdiv 2022-11-07 08:43:22 -08:00
David Green
b46427b9a2 [InstSimplify] (~A & B) | ~(A | B) --> ~A with logical and
According to https://alive2.llvm.org/ce/z/opsdrb, it is valid to convert
(~A & B) | ~(A | B) --> ~A even if the And is a Logical And. This came
up from the vector masking of predicated blocks.

Differential Revision: https://reviews.llvm.org/D137435
2022-11-07 10:03:18 +00:00
David Green
9e885d9aab [InstSimplify] Add tests for (~A & B) | ~(A | B) --> ~A with logical And. NFC 2022-11-07 09:04:06 +00:00
Daniel Sanders
021e6e05d3 [instsimplify] Move (extelt (inselt Vec, Value, Index), Index) -> Value from InstCombine
As requested in https://reviews.llvm.org/D135625#3858141

Differential Revision: https://reviews.llvm.org/D136099
2022-10-17 15:22:06 -07:00
Sanjay Patel
0a1210e482 [InstSimplify] try harder to fold fmul with 0.0 operand
https://alive2.llvm.org/ce/z/oShzr3

This was noted as a missing fold in D134876 (with additional
examples based on issue #58046).

I'm assuming that fmul with a zero operand is rare enough
that the use of ValueTracking will not noticeably increase
compile-time.

This adjusts a PowerPC codegen test that was added with D88388
because it would get folded away and no longer provide coverage
for the bug fix.
2022-10-04 11:20:01 -04:00
Sanjay Patel
b794d72bf4 [InstSimplify] add tests for fmul with 0.0 operand; NFC 2022-10-04 10:29:53 -04:00
Sanjay Patel
ba7da14d83 Revert "[InstSimplify] reduce code duplication for fmul folds; NFC"
This reverts commit 7b7940f9da.
This missed a test update.
2022-10-03 11:21:23 -04:00
Sanjay Patel
7b7940f9da [InstSimplify] reduce code duplication for fmul folds; NFC
The constant is already commuted for an fmul opcode,
but this code can be called more directly for fma,
so we have to swap for that caller. There are tests
in InstSimplify and InstCombine to verify that this
works as expected.
2022-10-03 10:36:02 -04:00
Sanjay Patel
4490cfbaf4 [ValueTracking] peek through fpext in isKnownNeverInfinity()
https://alive2.llvm.org/ce/z/BkNoRW
2022-10-02 11:20:23 -04:00
Sanjay Patel
0243b424d7 [InstSimplify] add tests for FP infinity compare with fpext; NFC 2022-10-02 11:20:23 -04:00
Arthur Eubanks
e23aee7175 [test] Update some legacy PM tests 2022-09-30 11:31:02 -07:00
Sanjay Patel
3f906f057c [InstSimplify] look through vector select (shuffle) in min/max fold
This is an extension of the existing min/max+select fold (which already
has a very large number of variations) to allow a vector shuffle because
that's what we have in the motivating example from issue #42100.

A couple of Alive2 checks of variants (I don't know how to generalize
these in Alive):
https://alive2.llvm.org/ce/z/jUFAqT

And verify the PR42100 test:
https://alive2.llvm.org/ce/z/3EcASf

It's possible there is some generalization of the fold or a
VectorCombine/SLP answer for the motivating test, but I haven't found a
better/smaller solution yet.

We can also add even more variants here as follow-up patches. For example,
we can have shuffle followed by min/max; we also don't have this
canonicalization or the reverse:
https://alive2.llvm.org/ce/z/StHD9f

Differential Revision: https://reviews.llvm.org/D134879
2022-09-30 08:27:00 -04:00
Sanjay Patel
8bfba17b40 [InstSimplify][PhaseOrdering] add tests for vector select of min/max; NFC
The phase ordering test is the almost unoptimized IR for the example
in issue #42100; it was passed through -mem2reg to reduce obvious
excessive load/store and other noise.

D134879
2022-09-29 12:06:55 -04:00
Nikita Popov
aa25c92f33 [ValueTracking] Fix CannotBeOrderedLessThanZero() for fdiv (PR58046)
When checking the RHS of fdiv, we should set the SignBitOnly flag,
because a negative zero can become -Inf, which is ordered less
than zero.

Fixes https://github.com/llvm/llvm-project/issues/58046.

Differential Revision: https://reviews.llvm.org/D134876
2022-09-29 17:07:48 +02:00
Nikita Popov
ea32658288 [InstSimplify] Add test for PR58046 (NFC) 2022-09-29 15:22:13 +02:00
Sanjay Patel
222e1c73f3 [InstSimplify] don't commute constant expression operand in min/max calls
The test shows that we would fail to consistently fold the
instruction based on the max value operand. This is also
the root cause for issue #57986, but I'll add an instcombine
test + assert for that exact problem in another commit.
2022-09-26 16:01:09 -04:00
Sanjay Patel
b5bccded2c [InstSimplify] add tests for max intrinsic with constant expression; NFC
This shows the root problem that leads to the crash in issue #57986.
2022-09-26 16:01:09 -04:00
Sanjay Patel
b0bfefb6ec [InstSimplify] fold redundant select of min/max, part 2
This extends e5d15e1162 to handle the inverse predicates
(there's probably a more elegant way to specify the preds).

These patterns correspond to the existing simplify:
max (min X, Y), X --> X
...and extra preds for (non)equality.

The tests cycle through all 10 icmp preds for each min/max
variant with 4 swapped operand patterns each (and the min/max
operands are commuted in every other test within those).

Some Alive2 examples to verify:
https://alive2.llvm.org/ce/z/XMvEKQ
https://alive2.llvm.org/ce/z/QpMChr
2022-09-25 07:06:43 -04:00
Sanjay Patel
e5d15e1162 [InstSimplify] fold redundant select of min/max
This is similar to the existing simplify:
max (max X, Y), X --> max X, Y
...but the select condition can be one of
several predicates as shown in the tests.

The tests cycle through all 10 icmp preds for
each min/max variant with 4 swapped operand
patterns each (and the min/max operands are
commuted in every other test within those).

Some Alive2 examples to verify:
https://alive2.llvm.org/ce/z/lCAQm4
https://alive2.llvm.org/ce/z/kzxVXC
2022-09-24 11:34:05 -04:00
Sanjay Patel
eb454433f4 [InstSimplify] add tests for select with min/max op; NFC
These are organized as 10 (predicates) * 4 (swapped operands) * 4 (min/max variants) = 160 tests.
2022-09-24 11:13:17 -04:00
Nikita Popov
41dde5d858 [InstSimplify] Support vectors in simplifyWithOpReplaced()
We can handle vectors inside simplifyWithOpReplaced(), as long as
cross-lane operations are excluded. The equality can hold (or not
hold) for each vector lane independently, so we shouldn't use the
replacement value from other lanes.

I believe the only operations relevant here are shufflevector (where
all previous bugs were seen) and calls (which might use shuffle-like
intrinsics and would require more careful classification).

Differential Revision: https://reviews.llvm.org/D134348
2022-09-22 10:45:42 +02:00