84 Commits

Author SHA1 Message Date
Matt Arsenault
1b235b087b ValueTracking: Add baseline tests for fcmp with non-0/inf constants
Currently assumes only do anything for fcmps that perform an exact
class test.
2023-09-11 20:03:03 +03:00
Philip Reames
294ad08ecc Revert "Revert "InstSimplify: Use correct interested FP classes when simplifying fcmp""
This reverts commit 89f0314ee14a4d7f5a92fd63574ba545863df016.  Change does not build.
2023-09-01 12:17:36 -07:00
Zequan Wu
89f0314ee1 Revert "InstSimplify: Use correct interested FP classes when simplifying fcmp"
Revert "InstSimplify: Add baseline tests for reported regression"
Revert "InstSimplify: Start cleaning up simplifyFCmpInst"

This reverts commit 0637b00041c7d6a191d51d9966c4f5f41fb97ab5.
This reverts commit 239fb206de35935416e652b89725d5f3193f78f5.
This reverts commit ddb3f12c428bc4bd5a98913d74dfd7f2402bdfd8.

These commits causes crashes when compiling chromium code, attached reduced ir at: https://reviews.llvm.org/D151887#4634914
2023-09-01 14:54:27 -04:00
Matt Arsenault
0637b00041 InstSimplify: Use correct interested FP classes when simplifying fcmp
We are interested in the cases that we don't want, so this was
backwards.

Fixes regression reported after ddb3f12c428bc4bd5a98913d74dfd7f2402bdfd8
2023-08-31 10:11:52 -04:00
Matt Arsenault
239fb206de InstSimplify: Add baseline tests for reported regression
Missed a fold after ddb3f12c428bc4bd5a98913d74dfd7f2402bdfd8
2023-08-31 10:11:52 -04:00
Matt Arsenault
ddb3f12c42 InstSimplify: Start cleaning up simplifyFCmpInst
Also picks up a few improvements (Some of the fcmp.ll
test names imply they aren't quite testing what was intended.
Checking the sign bit can't be performed with a compare to a 0).

Much of the logic in here is the same as the class detection
logic of fcmpToClassTest. We could unify more with a weaker
version of fcmpToClassTest which returns implied classes rather
than exact class-like compares. Also could unify more with detection
of possible classes in non-splat vectors.

One problem here is we now only perform folds that used
to always work now require a context instruction. This is
because fcmpToClassTest requires the parent function.
Either fcmpToClassTest could tolerate a missing context
function, or we could require passing in one to simplifyFCmpInst.
Without this it's possible to hit the !isNan assert (which feels like
an unnecessary assert). In any case, these cases don't appear in
any tests.

https://reviews.llvm.org/D151887
2023-08-30 11:53:05 -04: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
Matt Arsenault
13cf479dd1 ValueTracking: Use new version of cannotBeOrderedLessThanZero
Pass all arguments so now assumes work.
2023-06-23 19:26:30 -04:00
Matt Arsenault
4023ca1292 Reapply "InstSimplify: Pass AssumptionCache to isKnownNeverInfinity"
This reverts commit 481191b0a8318e55ce467e983d78d2141e827db1.
2023-05-23 08:48:25 +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 0012b94a4e8e0c757ef0adcd68fb61bb0318b26c.
Reverting due to test failures introduced by 73925ef8b0eacc6792f0e3ea21a3e6d51f5ee8b0
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
0012b94a4e InstSimplify: Pass AssumptionCache to isKnownNeverInfinity
Makes these cases work with assumes.
2023-05-19 00:48:03 +01:00
Matt Arsenault
8f111ecd75 InstSimplify: Split isKnownNeverInfinity tests into separate file
This fixes an annoying assymmetry in the test organization. We have
known-never-nan.ll for dedicated isKnownNeverNaN handling tests, but
the isKnownNeverInfinity were in floating-point-compare.ll. Move the
more targeted tests into a separate file to match.
2022-12-22 09:38:14 -05:00
Matt Arsenault
876f3d6c91 ValueTracking: Add test for isKnownNeverInfinity for fptrunc 2022-12-22 09:38:14 -05:00
Matt Arsenault
2c52c811ee ValueTracking: Document some difficult isKnownNeverInfinity cases
Add a comment and some negative tests. I'd like to have test coverage
and explicit handling of all the math operations for clarity.
2022-12-20 13:22:22 -05:00
Matt Arsenault
407b18820c ValueTracking: Add tests for isKnownNeverInfinity for llvm.log* 2022-12-20 13:17:03 -05:00
Matt Arsenault
2bf17cc048 ValueTracking: Teach isKnownNeverInfinity about llvm.sin/llvm.cos 2022-12-20 13:17:03 -05:00
Matt Arsenault
6d125fee8c ValueTracking: Add isKnownNeverInfinity tests for sin/cos 2022-12-20 13:17:03 -05:00
Matt Arsenault
9a21475651 ValueTracking: Teach isKnownNeverInfinity about sqrt 2022-12-20 13:03:07 -05:00
Matt Arsenault
b5963ea088 ValueTracking: Add base test for isKnownNeverInfinity of sqrt 2022-12-20 13:03:07 -05:00
Matt Arsenault
41dd02e857 ValueTracking: Teach isKnownNeverInfinity about min/max functions 2022-12-20 12:52:59 -05:00
Matt Arsenault
ef550ce361 ValueTracking: Add tests for isKnownNeverInfinity for min/max intrinsics 2022-12-20 12:52:59 -05:00
Matt Arsenault
4e37d00b9d ValueTracking: Teach isKnownNeverInfinity about rounding intrinsics 2022-12-20 12:45:07 -05:00
Matt Arsenault
2bfe62ed6a ValueTracking: Add tests for isKnownNeverInfinity for rounding intrinsics 2022-12-20 12:45:07 -05:00
Matt Arsenault
dac496fb1f ValueTracking: Teach isKnownNeverInfinity about arithmetic.fence 2022-12-05 08:39:07 -05:00
Matt Arsenault
af7e80b7cb ValueTracking: Look through copysign in isKnownNeverInfinity 2022-11-17 08:52:09 -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
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
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
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
Bjorn Pettersson
b280ee1dd7 [test] Use -passes=instsimplify instead of -instsimplify in a number of tests. NFC
Another step moving away from the deprecated syntax of specifying
pass pipeline in opt.

Differential Revision: https://reviews.llvm.org/D119080
2022-02-07 14:26:58 +01:00
Bjorn Pettersson
4c7f820b2b Update @llvm.powi to handle different int sizes for the exponent
This can be seen as a follow up to commit 0ee439b705e82a4fe20e2,
that changed the second argument of __powidf2, __powisf2 and
__powitf2 in compiler-rt from si_int to int. That was to align with
how those runtimes are defined in libgcc.
One thing that seem to have been missing in that patch was to make
sure that the rest of LLVM also handle that the argument now depends
on the size of int (not using the si_int machine mode for 32-bit).
When using __builtin_powi for a target with 16-bit int clang crashed.
And when emitting libcalls to those rtlib functions, typically when
lowering @llvm.powi), the backend would always prepare the exponent
argument as an i32 which caused miscompiles when the rtlib was
compiled with 16-bit int.

The solution used here is to use an overloaded type for the second
argument in @llvm.powi. This way clang can use the "correct" type
when lowering __builtin_powi, and then later when emitting the libcall
it is assumed that the type used in @llvm.powi matches the rtlib
function.

One thing that needed some extra attention was that when vectorizing
calls several passes did not support that several arguments could
be overloaded in the intrinsics. This patch allows overload of a
scalar operand by adding hasVectorInstrinsicOverloadedScalarOpd, with
an entry for powi.

Differential Revision: https://reviews.llvm.org/D99439
2021-06-17 09:38:28 +02:00
Sanjay Patel
645c53a9d9 [ValueTracking] enhance isKnownNeverInfinity to understand sitofp
As discussed in D87877, instcombine already has this fold,
but it was missing from the more general ValueTracking logic.

https://alive2.llvm.org/ce/z/PumYZP
2020-09-27 08:40:31 -04:00
Sanjay Patel
71f25ac8ca [InstSimplify] add tests for fcmp with casted op; NFC
This shows missing analysis in ValueTracking's isKnownNeverInfinity().
2020-09-27 08:36:57 -04:00
Sanjay Patel
b89ae102e6 [InstSimplify] fold fcmp using isKnownNeverInfinity + isKnownNeverNaN
Follow-up to D84035 / rG7393d7574c09.
This sidesteps a question of FMF/poison on fcmp raised in PR46077:
http://bugs.llvm.org/PR46077

https://alive2.llvm.org/ce/z/TCsyzD
  define i1 @src(float %x) {
  %0:
    %x42 = fadd nnan ninf float %x, 42.000000
    %r = fcmp ueq float %x42, inf
    ret i1 %r
  }
  =>
  define i1 @tgt(float %x) {
  %0:
    ret i1 0
  }
  Transformation seems to be correct!

https://alive2.llvm.org/ce/z/FQaH7a
  define i1 @src(i8 %x) {
  %0:
    %cast = uitofp i8 %x to float
    %r = fcmp one float inf, %cast
    ret i1 %r
  }
  =>
  define i1 @tgt(i8 %x) {
  %0:
    ret i1 1
  }
  Transformation seems to be correct!
2020-07-26 09:04:37 -04:00
Sanjay Patel
912e9e5262 [InstSimplify] add tests for fcmp with infinity constant; NFC 2020-07-26 09:04:36 -04:00
Sanjay Patel
7393d7574c [InstSimplify] fold fcmp with infinity constant using isKnownNeverInfinity
This is a step towards trying to remove unnecessary FP compares
with infinity when compiling with -ffinite-math-only or similar.
I'm intentionally not checking FMF on the fcmp itself because
I'm assuming that will go away eventually.
The analysis part of this was added with rGcd481136 for use with
isKnownNeverNaN. Similarly, that could be an enhancement here to
get predicates like 'one' and 'ueq'.

Differential Revision: https://reviews.llvm.org/D84035
2020-07-19 09:24:52 -04:00
Sanjay Patel
acbc688263 [InstSimplify] add tests for fcmp with infinity; NFC 2020-07-17 11:51:41 -04:00
Sanjay Patel
34d35d4a42 [ValueTracking] fix miscompile in maxnum case of cannotBeOrderedLessThanZeroImpl (PR46627)
A miscompile with -0.0 is shown in:
http://bugs.llvm.org/PR46627

This is because maxnum(-0.0, +0.0) does not specify a fixed result:
http://llvm.org/docs/LangRef.html#llvm-maxnum-intrinsic

So we need to tighten the constraints for when it is ok to say the
result of maxnum is positive (including +0.0).

Differential Revision: https://reviews.llvm.org/D83601
2020-07-14 08:08:09 -04:00
Sanjay Patel
9cc669d22d [InstCombine][InstSimplify] add tests for sign of maxnum; NFC
More coverage for D83601.
2020-07-14 08:08:09 -04:00
Sanjay Patel
2ad42c2653 [ValueTracking] improve analysis for fdiv with same operands
(The 'nnan' variant of this pattern is already tested to produce '1.0'.)

https://alive2.llvm.org/ce/z/D4hPBy

define i1 @src(float %x, i32 %y) {
%0:
  %d = fdiv float %x, %x
  %uge = fcmp uge float %d, 0.000000
  ret i1 %uge
}
=>
define i1 @tgt(float %x, i32 %y) {
%0:
  ret i1 1
}
Transformation seems to be correct!
2020-06-21 09:07:59 -04:00
Sanjay Patel
97c0232621 [InstSimplify] add test for fdiv signbit; NFC 2020-06-21 09:07:59 -04:00