Commit Graph

129 Commits

Author SHA1 Message Date
Florian Hahn 6db71b8f14
[ConstraintElim] Use helper to allow overflow for coefficients of GEPs
If the arithmetic for indices of inbounds GEPs overflows, the result is
poison. This means it is also OK for the coefficients to overflow. GEP
decomposition is limited to cases where the index size is <= 64 bit,
which can be represented by int64_t used for the coefficients in the
constraint system.
2022-10-17 20:30:43 +01:00
Florian Hahn aec0c1009f
[ConstraintElim] Replace custom GEP index handling by using existing code
Instead of duplicating the existing decomposition code for GEP indices
just use the existing code by calling the existing decompose function on
the index expression and multiply the result's coefficients by the scale of
the index.

This both reduces code duplication and generalizes the pattern we can
handle.
2022-10-16 21:53:11 +01:00
Florian Hahn a4635ec710
[ConstraintElim] Support `add nsw` for unsigned preds with positive ops.
If both operands of an `add nsw` are known positive, it can be treated
the same as `add nuw` and added to the unsigned system.

https://alive2.llvm.org/ce/z/6gprff
2022-10-16 20:25:14 +01:00
Florian Hahn 067b744dbb
[ConstraintElim] Add tests for add nsw with unsigned predicates. 2022-10-16 15:51:33 +01:00
Florian Hahn 7c1b80e35c
[ConstraintElim] Support unsigned decomposition of mul/shl nuw..const
Support decomposition for `mul/shl nuw` with constant operand for unsigned
queries. Those expressions should not wrap in the unsigned sense and can
be added directly to the unsigned system.
2022-10-15 21:28:08 +01:00
Florian Hahn f12684d36e
[ConstraintElim] Support signed decomposition of `add nsw`.
Add support decomposition for `add nsw` for signed queries.
`add nsw` won't wrap and can be directly added to the signed
system.
2022-10-15 18:34:03 +01:00
Florian Hahn fb3e2bef4c
[ConstraintElim] Add test cases for shl and mul. 2022-10-14 16:59:13 +01:00
Florian Hahn 572d5d374c
[ConstraintElim] Add support for GEPs with multiple indices.
Lift restriction on GEPs with a single index by iterating over all
indices and joining the {Coefficient, Variable} entries for all indices
together.
2022-10-13 21:08:33 +01:00
Florian Hahn 52fdbbd86d
[ConstraintElim] Add nested GEP test with scalable vectors. 2022-10-13 20:58:11 +01:00
Florian Hahn 359bc5c541
[ConstraintElim] Bail out for GEPs when index size > 64 bits.
Limit pointer decomposition to pointers with index sizes of at most 64
bits. int64_t is used for coefficients, so as long as the index size <=
64 bits we should be able to represent all pointer offsets.

Pointer decomposition is limited to inbounds GEPs, so if a index
computation would overflow the result is poison, so it doesn't matter
that the coefficient overflows.

This allows replacing MulOverflow with regular multiplications.
2022-10-13 10:19:30 +01:00
Florian Hahn e143e52c22
[ConstraintElimination] Add tests with 128 bit pointers. 2022-10-12 19:49:29 +01:00
Florian Hahn ebb0be9b68
[ConstraintElimination] Regenerate check lines for test.
Thanks @nikic for spotting that!
2022-10-10 20:23:25 +01:00
Florian Hahn 80e49f49e4
[ConstraintElimination] Bail out for GEPs with scalable vectors.
This fixes a crash with scalable vectors, thanks @nikic for spotting
this!
2022-10-10 16:01:20 +01:00
Florian Hahn fee8f561bd
[ConstraintElimination] Include index type scale.
The current decomposition for GEPs did not correctly handle cases where
GEPs access different source types. Adjust the constraints by including
the indexed type-size as coefficients.

Further generalization to allow GEPs with more than one index is a
needed general follow-up improvement.
2022-10-09 21:53:30 +01:00
Florian Hahn a40fdef734
[ConstraintElimination] Add tests for GEPs with different source types. 2022-10-09 21:51:47 +01:00
Florian Hahn 11a6e64ba7
[ConstraintElim] Move logic to get constraint for solving to helper.
Move common logic shared by callers of getConstraint that use the result
to query the constraint system to a new helper getConstraintForSolving.

This includes common legality checks (i.e. not an equality constraint,
no new variables) and the logic to query the unsigned system if possible
for signed predicates.
2022-10-09 10:44:36 +01:00
Florian Hahn 1ae405144d
[ConstraintElimination] Add tests for chained GEPs without inbounds. 2022-10-08 19:39:37 +01:00
Florian Hahn e0136a62cc
[ConstraintElimination] Support chained GEPs with constant offsets.
Handle the (gep (gep ....), C) case by incrementing the constant
coefficient of the inner GEP, if C is a constant.
2022-10-08 16:59:27 +01:00
Florian Hahn 9d31d1c214
[ConstraintElimination] Use logic from 3771310eed for queries only.
The logic added in 3771310eed was placed sub-optimally. Applying the
transform in ::getConstraint meant that it would also impact conditions
that are added to the system by the signed <-> unsigned transfer logic.

This meant we failed to add some signed facts to the signed system. To
make sure we still add as many useful facts to the signed/unsigned
systems, move the logic to the point where we query the system.
2022-10-08 11:03:45 +01:00
Florian Hahn d227029ce4
[ConstraintElimination] Add test for regression after 3771310eed. 2022-10-07 20:42:16 +01:00
Florian Hahn 3771310eed
[ConstraintElimination] Convert to unsigned Pred if possible.
Convert SLE/SLT predicates to unsigned equivalents if both operands are
known to be signed-positive.

https://alive2.llvm.org/ce/z/tBeiZr
2022-10-07 12:27:36 +01:00
Florian Hahn 1ad58989ee
[ConstraintElimination] Add test that crash in earlier var handling.
Add a test that caused a crash in the new variable handling code in
earlier versions.
2022-10-07 09:31:45 +01:00
Florian Hahn 5b70db8f00
[ConstraintElimination] Add tests where unsigned system can be queried.
Add tests with a mix of signed and unsigned predicates. In some cases,
the unsigned system can be queried for signed predicates to improve
results.
2022-10-06 22:11:51 +01:00
Florian Hahn c9fa457933
[ConstraintElimination] Remove fixme addressed in 8e3e96298f. 2022-10-06 18:24:50 +01:00
Florian Hahn c5e1ddb6fd
[ConstraintElimination] Update tests to use opaque pointers. 2022-10-06 18:07:25 +01:00
Florian Hahn a7ac0dd0cf
[ConstraintElimination] Generalize AND matching.
Extend more general matching used for chains of ORs to also support
chains of ANDs.
2022-10-06 17:17:38 +01:00
Florian Hahn 8e3e96298f
[ConstraintElimination] Order cmps for signed <-> unsigned transfer first.
Make sure conditions with constant operands come before conditions
without constant operands. This increases the effectiveness of the
current signed <-> unsigned fact transfer logic.
2022-10-06 15:56:25 +01:00
Florian Hahn a2f96a10cf
[ConstraintElimination] Add tests with logical ANDs. 2022-10-06 14:50:13 +01:00
Florian Hahn 349375d093
[ConstraintElimination] Generalize OR matching.
Extend OR handling to traverse chains of ORs.
2022-10-06 11:56:22 +01:00
Florian Hahn e09b0589a9
[ConstraintElimination] Extend test coverage for AND chains. 2022-10-06 09:11:08 +01:00
Florian Hahn cceb8c068d
[ConstraintElimination] Extend test coverage for OR chains. 2022-10-06 08:39:11 +01:00
Florian Hahn c1bfa41428
[ConstraintElimination] Add test for debug printing. 2022-10-03 20:56:39 +01:00
Florian Hahn 22fe40068c
[ConstraintElimination] Add tests for chained GEPs with const offsets.
Add extra tests for chained GEPs where the second GEP has a constant
offset. Inspired by missed optimizations from #51358.
2022-10-03 15:55:36 +01:00
Max Kazantsev a34b5212ec [Test] Add test showing that Constraint Elimination can deal with case where SCEV fails 2022-10-03 16:41:22 +07:00
Florian Hahn 3fe6ddd999
[ConstraintElimination] Update Changed status in ssub simplification.
Update tryToSimplifyOverflowMath to indicate whether the function made
any changes to the IR.
2022-10-02 14:25:51 +01:00
Florian Hahn 586784a2e4
[ConstraintElimination] Simplify check lines in test added in 2812a141.
The CHECK lines in the test are too specific and cause mis-matches on
some platforms. Reduce them to make them less fragile.
2022-09-30 19:51:05 +01:00
Florian Hahn 2812a1413f
[ConstraintElimination] Add test showing bug in analysis invalidation. 2022-09-30 19:37:58 +01:00
Florian Hahn 04c711c78d
[ConstraintElimination] Make sure the variable is available before use.
This fixes a crash when trying to access an index for a value where we
don't have a known index.

Fixes #58009.
2022-09-30 18:09:01 +01:00
Zain Jaffal aac6629f6d
[ConstraintElimination] Add initial usub.with.overflow tests.
Optimizations can be used to eliminate unecessary overflow checks. This patch introduces some test cases where the checks can be safely removed

Reviewed By: fhahn, fcloutier

Differential Revision: https://reviews.llvm.org/D134038
2022-09-26 16:44:36 +01:00
Florian Hahn 7914e53e31
[ConstraintElimination] Fix crash when combining results.
f213128b29 didn't account for the possibility that the result of
decompose may be empty. Fix that by explicitly checking. Use a newly
introduced helper to also reduce some duplication.

Thanks @bjope for finding the issue!
2022-09-17 14:47:38 +01:00
Florian Hahn 7f3ff9d3c0
[ConstraintElimination] Track if variables are positive in constraint.
Keep track if variables are known positive during constraint
decomposition, aggregate the information when building the constraint
object and encode the extra information as constraints to be used during
reasoning.
2022-09-14 18:43:54 +01:00
Florian Hahn f213128b29
[ConstraintElimination] Further de-compose operands of add operations.
This simply extends the existing logic to look through adds and combine
the components as done in other places already.
2022-09-14 12:00:32 +01:00
Florian Hahn aba2085e52
[ConstraintElimination] Add tests where info from zext can be used. 2022-09-14 10:04:07 +01:00
Florian Hahn 62c1928437
[ConstraintElimination] Add tests for chained adds.
Add test coverage for reasoning about chains of adds.
2022-09-14 09:27:18 +01:00
Florian Hahn 92f87787b3
Recommit "[ConstraintElimination] Transfer info from ULT to signed system."
This reverts commit 94ed2caf70.

The issue with no-determinism with the test has been fixed in
d9526e8a52.
2022-06-24 09:27:14 +02:00
Florian Hahn 94ed2caf70
Revert "[ConstraintElimination] Transfer info from ULT to signed system."
This reverts commit 316e106f49.

This breaks a bot with expensive checks.
2022-06-23 17:27:33 +02:00
Florian Hahn 316e106f49
[ConstraintElimination] Transfer info from ULT to signed system.
If A u< B holds, then A s>= 0 && A s< B holds if B s>= 0.

https://alive2.llvm.org/ce/z/RrNxHh
2022-06-23 17:17:01 +02:00
Florian Hahn 9a33f3975e
[ConstraintElimination] Transfer info from SLT to unsigned system.
If A s< B holds, then A u< also holds, if A s>= 0.

https://alive2.llvm.org/ce/z/J4JZuN
2022-06-23 15:57:59 +02:00
Florian Hahn 24a98881cd
[ConstraintElimination] Transfer info from SGT to unsigned system.
If A >s B then A >=u 0, if B >=s -1.

https://alive2.llvm.org/ce/z/cncGKi
2022-06-23 11:04:51 +02:00
Florian Hahn 098b0b18a7
[ConstraintElimination] Transfer info from SGE to unsigned system.
This patch adds a new transferToOtherSystem helper that tries to
transfer information from signed predicates to the unsigned system and
vice versa.

The initial version adds A >=u B for A >=s B && B >=s 0

https://alive2.llvm.org/ce/z/8b6F9i
2022-06-22 15:27:59 +02:00