Commit Graph

1009 Commits

Author SHA1 Message Date
Zhongyunde
05aae0839f Reland [AArch64][NFC] Call the API getVScaleRange directly
Use the maximum 64 for BitWidth of getVScaleRange to avoid returning an empty range.

the previous changes bring in a Buildbot failure because MinSVEVectorSize = MinSVEVectorSize.
    error: explicitly assigning value of variable of type 'unsigned int' to itself [-Werror,-Wself-assign]

Reviewed By: sdesmalen, nikic, dmgreen
Differential Revision: https://reviews.llvm.org/D155708
2023-07-26 18:55:31 +08:00
Zhongyunde
ebaac2b2d6 Revert "[AArch64][NFC] Call the API getVScaleRange directly"
This reverts commit 67005c8e6f.
2023-07-26 16:44:14 +08:00
Zhongyunde
67005c8e6f [AArch64][NFC] Call the API getVScaleRange directly
Use the maximum 64 for BitWidth of getVScaleRange to
avoid returning an empty range.

Reviewed By: sdesmalen, nikic, dmgreen
Differential Revision: https://reviews.llvm.org/D155708
2023-07-26 15:54:04 +08:00
Nikita Popov
0db5d8e123 Reapply [InstSimplify] Make simplifyWithOpReplaced() recursive (PR63104)
A similar assumption as for the x^x case also existed for the absorber
case, which lead to a stage2 miscompile. That assumption is not fixed.

-----

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 and the absorber special case, we
can no longer assume that one of the operands 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-18 10:36:39 +02:00
Matt Arsenault
29d2a9bf9d InstSimplify: Handle basic folds for frexp
Handle constant folding and idempotent folding. Not sure
this is an appropriate use of undef for the inf/nan case. The
C version says the second result is "unspecified". The AMDGPU
instruction returns 0.
2023-07-17 17:28:01 -04:00
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
e21ccdcd98 [InstSimplify] Revert unintentional change
This change was made as part of 91b84811ab,
which was only supposed to add tests.
2023-07-14 16:27:49 +02:00
Nikita Popov
547544112b [InstSimplify] Allow gep inbounds x, 0 -> x in non-refining op replacement
After the semantics change from https://reviews.llvm.org/D154051,
gep inbounds x, 0 can no longer produce poison. As such, we can
also perform this fold during non-refining operand replacement
and avoid unnecessary drops of the inbounds flag.

The online alive2 version has not been update to the new
semantics yet, but we can use the following proof locally:

    define ptr @src(ptr %base, i64 %offset) {
      %cmp = icmp eq i64 %offset, 0
      %gep = getelementptr inbounds i8, ptr %base, i64 %offset
      %sel = select i1 %cmp, ptr %base, ptr %gep
      ret ptr %sel
    }

    define ptr @tgt(ptr %base, i64 %offset) {
      %gep = getelementptr inbounds i8, ptr %base, i64 %offset
      ret ptr %gep
    }
2023-07-14 16:14:50 +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
61e0822efa [llvm][clang] Remove uses of isOpaquePointerTy() (NFC)
This now always returns true (for pointer types).
2023-07-14 10:27:58 +02:00
Matt Arsenault
0f4eb557e8 ValueTracking: Replace CannotBeNegativeZero
This is now just a wrapper around computeKnownFPClass.
2023-07-12 13:14: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
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
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
Nikita Popov
793eb0c0e4 [InstSimplify] Make sure offsets have same size in computePointerICmp()
The way this is currently implemented the accumulated offsets can
end up having a different size, which causes unnecessary
complication for further extension of the code.

Don't strip pointer casts at the start and rely on
stripAndAccumulate to do any necessary stripping. It gracefully
handles different index sizes and will always retain the width of
the original pointer index type.

This is not NFC, but unlikely to make any practical difference.
2023-06-27 15:20:55 +02: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
Arthur Eubanks
d202bc7235 Revert "Revert "InstSimplify: Remove null parent checks""
This reverts commit 935c8b6f3a.

Going to fix forward size regression instead due to more dependent patches needing to be reverted otherwise.
2023-06-16 13:53:31 -07:00
Arthur Eubanks
3e39cfe5b4 Revert "Revert "InstSimplify: Require instruction be parented""
This reverts commit 0c03f48480.

Going to fix forward size regression instead due to more dependent patches needing to be reverted otherwise.
2023-06-16 13:53:31 -07:00
Arthur Eubanks
0c03f48480 Revert "InstSimplify: Require instruction be parented"
This reverts commit 1536e299e6.

Causes large binary size regressions, see comments on https://reviews.llvm.org/rG1536e299e63d7788f38117b0212ca50eb76d7a3b.
2023-06-16 11:24:29 -07:00
Arthur Eubanks
935c8b6f3a Revert "InstSimplify: Remove null parent checks"
This reverts commit 2ca21e8775.

Dependent commit to be reverted
2023-06-16 11:24:28 -07:00
Alan Zhao
d6b4f6786b Revert "Revert "InstSimplify: Require instruction be parented""
This reverts commit 00264eac4d.

Reason: caused a bunch of bots to break
2023-06-16 10:58:54 -07:00
Alan Zhao
00264eac4d Revert "InstSimplify: Require instruction be parented"
This reverts commit 1536e299e6.

Reason: causes a regression in the inliner (see https://crbug.com/1454531 and https://reviews.llvm.org/rG1536e299e63d7788f38117b0212ca50eb76d7a3b#1217141)
2023-06-16 10:36:49 -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
Matt Arsenault
2ca21e8775 InstSimplify: Remove null parent checks
The feature to operate on incomplete IR was barely used
an poorly tested.
2023-06-02 18:14:28 -04:00
Matt Arsenault
1536e299e6 InstSimplify: Require instruction be parented
Unlike every other analysis and transform, simplifyInstruction
permitted operating on instructions which are not inserted
into a function. This created an edge case no other code needs
to really worry about, and limited transforms in cases that
can make use of the context function. Only the inliner and a handful
of other utilities were making use of this, so just fix up these
edge cases. Results in some IR ordering differences since
cloned blocks are inserted eagerly now. Plus some additional
simplifications trigger (e.g. some add 0s now folded out that
previously didn't).
2023-06-02 18:14:28 -04:00
Matt Arsenault
4023ca1292 Reapply "InstSimplify: Pass AssumptionCache to isKnownNeverInfinity"
This reverts commit 481191b0a8.
2023-05-23 08:48:25 +01:00
Matt Arsenault
1e34a17926 Reapply "InstSimplify: Use isKnownNeverInfOrNaN"
This reverts commit f55224735e.
2023-05-23 08:48:25 +01:00
Alina Sbirlea
f55224735e Revert "InstSimplify: Use isKnownNeverInfOrNaN"
This reverts commit 494dee0f7a.
Related to the other reverts, causes test failure due to nan/inf
mismatch.
2023-05-19 22:27:42 -07: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
494dee0f7a InstSimplify: Use isKnownNeverInfOrNaN 2023-05-18 23:29:47 +01:00
Matt Arsenault
07365f4a40 InstSimplify: Combine computeKnownFPClass calls and pass AssumptionCache 2023-05-18 23:29:47 +01:00
Matt Arsenault
faa32734bf SimplifyLibCalls: Pass AssumptionCache to isKnownNeverInfinity
Let's assumes work for determining no infinities.
2023-05-18 19:44:56 +01: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
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
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
Noah Goldstein
ab1b42ac5c [InstCombine] Add simplifications for div/rem with i1 operands; PR62607
This is generally handled already in early CSE.

If a specialized pipeline is used, however, its possible for `i1`
operand with known-zero denominator to slip through. Generally the
known-zero denominator is caught and poison is returned, but if it is
indirect enough (known zero through a phi node) we can miss this case
in `InstructionSimplify` and then miss handling `i1`. This is because
`i1` is current handled with the following check:
    `if(Known.countMinLeadingZeros() == Known.getBitWidth() - 1)`

which only works on the assumption we don't know the denominator to be
zero. If we know the denominator to be zero, this check fails:
https://github.com/llvm/llvm-project/issues/62607

This patch simply adds an explicit `if(Known.isZero) return poison;`
which fixes the issue.

Alive2 Link for tests:
    https://alive2.llvm.org/ce/z/VTw54n

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D150142
2023-05-13 14:35:57 -05: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
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
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
b80f31c48d [InstSimplify] with logical ops: (X | Y) ? 0 : X --> 0
Use simplifySelectWithICmpEq to handle the implied equalities from the icmp-or,
then both of ICMP_NE and ICMP_EQ will be addressed
  (X | Y) == 0 ?  X : 0 --> 0 (commuted 2 ways)
  (X | Y) != 0 ?  0 : X --> 0 (commuted 2 ways)
Fixes https://github.com/llvm/llvm-project/issues/62263

Reviewed By: nikic, RKSimon
Differential Revision: https://reviews.llvm.org/D148986
2023-04-25 21:51:41 +08:00