1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00
Commit Graph

150 Commits

Author SHA1 Message Date
Philip Reames
c349ecadfa Recommit "Generalize getInvertibleOperand recurrence handling slightly"
This was reverted because of a reported problem.  It turned out this patch didn't introduce said problem, it just exposed it more widely.  15a4233 fixes the root issue, so this simple a) rebases over that, and b) adds a much more extensive comment explaining why that weakened assert is correct.

Original commit message follows:

Follow up to D99912, specifically the revert, fix, and reapply thereof.

This generalizes the invertible recurrence logic in two ways:
* By allowing mismatching operand numbers of the phi, we can recurse through a pair of phi recurrences whose operand orders have not been canonicalized.
* By allowing recurrences through operand 1, we can invert these odd (but legal) recurrence.

Differential Revision: https://reviews.llvm.org/D100884
2021-05-03 16:40:56 -07:00
Philip Reames
b123d90a62 One more test case inspired by PR50191 2021-05-03 16:23:04 -07:00
Philip Reames
f5c6ef2e13 Add some additional test cases inspired by PR50191 2021-05-03 15:56:37 -07:00
Philip Reames
a17954e6f1 Revert "Generalize getInvertibleOperand recurrence handling slightly"
This reverts commit 0c01b37eeb18a51a7e9c9153330d8009de0f600e while a problem reported is investigated.
2021-04-29 13:06:26 -07:00
Philip Reames
5b3993fcf6 Generalize getInvertibleOperand recurrence handling slightly
Follow up to D99912, specifically the revert, fix, and reapply thereof.

This generalizes the invertible recurrence logic in two ways:
* By allowing mismatching operand numbers of the phi, we can recurse through a pair of phi recurrences whose operand orders have not been canonicalized.
* By allowing recurrences through operand 1, we can invert these odd (but legal) recurrence.

Differential Revision: https://reviews.llvm.org/D100884
2021-04-28 14:38:07 -07:00
Philip Reames
e5f1391c16 [tests] Precommit some extra tests for D100884 2021-04-28 13:46:35 -07:00
Philip Reames
6215df8065 Reapply "Look through invertible recurrences in isKnownNonEqual"
I'd reverted this in commit 3b6acb179708ea2f3caf95ace0f134fcbc460333 due to buildbot failures.  This patch contains the fix for said issue.  I'd forgotten to handle the case where two phis in the same block have different operand order.  We canonicalize away from this, but it's still valid IR.  The tests included in this change (as opposed to simply having test output changed), crashed without the fix.

Original commit message follows...

This extends the phi handling in isKnownNonEqual with a special case based on invertible recurrences. If we can prove the recurrence is invertible (which many common ones are), we can recurse through the start operands of the recurrence skipping the phi cycle.

(Side note: Instcombine currently does not push back through these cases. I will implement that in a follow up change w/separate review.)

Differential Revision: https://reviews.llvm.org/D99912
2021-04-20 12:47:59 -07:00
Philip Reames
952b6e81cd Revert "Look through invertible recurrences in isKnownNonEqual"
This reverts commit be20eae25f50f5ef648aeefa1143e1c31e4410fc.  It appears to have caused a crash on a buildbot (https://lab.llvm.org/buildbot#builders/77/builds/5653).  Reverting while investigating.
2021-04-20 11:47:10 -07:00
Philip Reames
c647071b9b Look through invertible recurrences in isKnownNonEqual
This extends the phi handling in isKnownNonEqual with a special case based on invertible recurrences. If we can prove the recurrence is invertible (which many common ones are), we can recurse through the start operands of the recurrence skipping the phi cycle.

(Side note: Instcombine currently does not push back through these cases. I will implement that in a follow up change w/separate review.)

Differential Revision: https://reviews.llvm.org/D99912
2021-04-20 10:52:22 -07:00
Philip Reames
355ef90ae5 [test] Add a couple more tests for D99912 2021-04-20 09:56:57 -07:00
Philip Reames
ffc966130f [tests] Update per review comment on D99912
(I'd copy and pasted the wrong test before tweaking, as a result, it wasn't a very good negative test.)
2021-04-20 09:42:29 -07:00
Nikita Popov
e6b1858425 [ValueTracking] Don't require strictly positive for mul nsw recurrence
Just like in the mul nuw case, it's sufficient that the step is
non-zero. If the step is negative, then the values will jump
between positive and negative, "crossing" zero, but the value of
the recurrence is never actually zero.
2021-04-14 19:39:59 +02:00
Nikita Popov
14134a9eac [ValueTracking] Don't require non-zero step for add nuw
It's okay if the step is zero, we'll just stay at the same non-zero
value in that case. The valuable part of this is that the step
doesn't even need to be a constant anymore.
2021-04-14 19:06:18 +02:00
Nikita Popov
a837647531 [ValueTracking] Add additional non-zero add recurrence test (NFC)
Also drop a number of unused parameters from existing tests.
2021-04-14 19:06:18 +02:00
Philip Reames
103039b1aa Exact ashr/lshr don't loose any set bits and are thus trivially invertible
Use that fact to improve isKnownNonEqual.
2021-04-05 19:22:36 -07:00
Philip Reames
5c362c1cd5 Fix copy paste errors in tests from be11bd1e
Several of these weren't testing what was intented.
2021-04-05 12:38:36 -07:00
Philip Reames
126765f727 [tests] Precommmit tests for reasoning about equality of recurrences 2021-04-05 12:14:05 -07:00
Philip Reames
5a0375405f [ValueTracking] Handle non-zero ashr/lshr recurrences
If we know we don't shift out bits (e.g. exact), all we need to know is that input is non-zero.
2021-03-31 16:48:32 -07:00
Philip Reames
e571959eb5 [tests] Add tests for ashr/lshr recurrences in isKnownNonZero 2021-03-31 16:48:32 -07:00
Nikita Popov
86d338c7f7 [ValueTracking] Handle shl pair in isKnownNonEqual()
Handle (x << s) != (y << s) where x != y and the shifts are
non-wrapping. Once again, this establishes parity with the
corresponing mul fold that already exists. The shift case is
more powerful because we don't need to guard against multiplies
by zero.
2021-03-26 20:21:05 +01:00
Nikita Popov
81d01bceaa [ValueTracking] Handle shl in isKnownNonEqual()
This handles the pattern X != X << C for non-zero X and C and a
non-overflowing shift. This establishes parity with the corresponing
fold for multiplies.
2021-03-26 20:21:05 +01:00
Nikita Popov
81173d98df [ValueTracking] Add tests for non equal shifts (NFC) 2021-03-26 20:21:05 +01:00
Nikita Popov
56b9e804f2 [ValueTracking] Handle non-zero shl recurrence
In this case we don't care about the step at all, and only require
that the starting value is non-zero.
2021-03-26 18:39:06 +01:00
Nikita Popov
07f0265381 [ValueTracking] Add tests for non-zero shl recurrences (NFC) 2021-03-26 18:35:38 +01:00
Nikita Popov
0926f8f2a9 [ValueTracking] Handle non-zero add/mul recurrences more precisely
This is mainly for clarity: It doesn't make sense to do any
negative/positive checks when dealing with a nuw add/mul. These
only make sense to nsw add/mul.
2021-03-26 18:30:07 +01:00
Nikita Popov
eb6c470c5f [ValueTracking] Add more non-zero add/mul recurrence tests (NFC) 2021-03-26 18:30:07 +01:00
Jingu Kang
a1f6b21702 [ValueTracking] Handle two PHIs in isKnownNonEqual()
loop:
  %cmp.0 = phi i32 [ 3, %entry ], [ %inc, %loop ]
  %pos.0 = phi i32 [ 1, %entry ], [ %cmp.0, %loop ]
  ...
  %inc = add i32 %cmp.0, 1
  br label %loop

On above example, %pos.0 uses previous iteration's %cmp.0 with backedge
according to PHI's instruction's defintion. If the %inc is not same among
iterations, we can say the two PHIs are not same.

Differential Revision: https://reviews.llvm.org/D98422
2021-03-25 22:56:05 +00:00
Philip Reames
c967c78fcf [deref] Handle byval/byref/sret/inalloc/preallocated arguments for deref-at-point semantics
All of these are scoped allocations which remain dereferenceable during the lifetime of the callee.

Differential Revision: https://reviews.llvm.org/D99310
2021-03-25 14:47:31 -07:00
Philip Reames
006e14ce80 [deref] Implement initial set of inference rules for deref-at-point
This implements a subset of the initial set of inference rules proposed in the llvm-dev thread "RFC: Decomposing deref(N) into deref(N) + nofree". The nolias one got moved to a separate review as there was some concerns raised which require further discussion.

Differential Revision: https://reviews.llvm.org/D99135
2021-03-24 16:20:41 -07:00
Jingu Kang
af9f082c95 [ValueTracking] Handle increasing mul recurrence in isKnownNonZero()
Differential Revision: https://reviews.llvm.org/D99069
2021-03-23 23:04:41 +00:00
Philip Reames
ba66e19f46 [test] precommit another test for point-in-time deref semantics 2021-03-22 19:11:19 -07:00
Philip Reames
053fdd1b0a [tests] Expand tests for point-in-time dereferenceability 2021-03-22 18:56:57 -07:00
Philip Reames
a2cee22477 [deref] Split a test to show both global and pointwise semantics
While doing so, also split one monster test into individually named test functions.
2021-03-22 18:34:40 -07:00
Nikita Popov
f63d7f1a92 [ValueTracking] Regenerate test checks (NFC) 2021-03-22 22:26:00 +01:00
Philip Reames
4a8ddcfff5 Autogen some tests for ease of update 2021-03-22 11:06:29 -07:00
Nikita Popov
60f065900e [ValueTracking] Improve mul handling in isKnownNonEqual()
X != X * C is true if:
 * C is not 0 or 1
 * X is not 0
 * mul is nsw or nuw

Proof: https://alive2.llvm.org/ce/z/uwF29z

This is motivated by one of the cases in D98422.
2021-03-21 18:41:35 +01:00
Nikita Popov
312855ffec [ValueTracking] Add more tests for isKnownNonEqual() of mul (NFC)
This is for the case of (x * C) == x, rather than the
(x * C1) == (x * C2) variant that we already cover.
2021-03-21 18:41:35 +01:00
Tyker
443904009e reland [InstCombine] convert assumes to operand bundles
Instcombine will convert the nonnull and alignment assumption that use the boolean condtion
to an assumption that uses the operand bundles when knowledge retention is enabled.

Differential Revision: https://reviews.llvm.org/D82703
2021-02-13 13:03:11 +01:00
Philip Reames
2bc932f596 [knownbits] Preserve known bits for small shift recurrences
The motivation for this is that I'm looking at an example that uses shifts as induction variables. There's lots of other omissions, but one of the first I noticed is that we can't compute tight known bits. (This indirectly causes SCEV's range analysis to produce very poor results as well.)

Differential Revision: https://reviews.llvm.org/D96440
2021-02-11 17:56:36 -08:00
Philip Reames
e71408afd4 [tests] Precommit tests for D96440 2021-02-11 10:48:07 -08:00
Tyker
919f469bdb Revert "[InstCombine] convert assumes to operand bundles"
This reverts commit 5eb2e994f9b3a5aff0a156d0a1f7e6121342cc11.
2021-02-10 01:32:00 +01:00
Tyker
76d5e82203 [InstCombine] convert assumes to operand bundles
Instcombine will convert the nonnull and alignment assumption that use the boolean condtion
to an assumption that uses the operand bundles when knowledge retention is enabled.

Differential Revision: https://reviews.llvm.org/D82703
2021-02-09 19:33:53 +01:00
Juneyoung Lee
c70101b156 Allow nonnull/align attribute to accept poison
Currently LLVM is relying on ValueTracking's `isKnownNonZero` to attach `nonnull`, which can return true when the value is poison.
To make the semantics of `nonnull` consistent with the behavior of `isKnownNonZero`, this makes the semantics of `nonnull` to accept poison, and return poison if the input pointer isn't null.
This makes many transformations like below legal:

```
%p = gep inbounds %x, 1 ; % p is non-null pointer or poison
call void @f(%p)        ; instcombine converts this to call void @f(nonnull %p)
```

Instead, this semantics makes propagation of `nonnull` to caller illegal.
The reason is that, passing poison to `nonnull` does not immediately raise UB anymore, so such program is still well defined, if the callee does not use the argument.
Having `noundef` attribute there re-allows this.

```
define void @f(i8* %p) {       ; functionattr cannot mark %p nonnull here anymore
  call void @g(i8* nonnull %p) ; .. because @g never raises UB if it never uses %p.
  ret void
}
```

Another attribute that needs to be updated is `align`. This patch updates the semantics of align to accept poison as well.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D90529
2021-01-20 11:31:23 +09:00
Nikita Popov
78e2ca16be [ValueTracking] Fix isKnownNonEqual() with constexpr mul
Confusingly, BinaryOperator is not an Operator,
OverflowingBinaryOperator is... We were implicitly assuming that
the multiply is an Instruction here.

This fixes the assertion failure reported in
https://reviews.llvm.org/D92726#2472827.
2020-12-28 18:32:57 +01:00
Philip Reames
68207a0a0f Teach isKnownNonEqual how to recurse through invertible multiplies
Build on the work started in 8f07629, and add the multiply case. In the process, more clearly describe the requirement for the operation we're looking through.

Differential Revision: https://reviews.llvm.org/D92726
2020-12-07 14:52:08 -08:00
Philip Reames
2255584563 Add recursive decomposition reasoning to isKnownNonEqual
The basic idea is that by looking through operand instructions which don't change the equality result that we can push the existing known bits comparison down past instructions which would obscure them.

We have analogous handling in InstSimplify for most - though weirdly not all - of these cases starting from an icmp root. It's a bit unfortunate to duplicate logic, but since my actual goal is to extend BasicAA, the icmp logic doesn't help. (And just makes it hard to test here.)  The BasicAA change will be posted separately for review.

Differential Revision: https://reviews.llvm.org/D92698
2020-12-05 15:58:19 -08:00
Philip Reames
90a18e8a99 [test] precommit test for D92698 2020-12-04 15:17:39 -08:00
Arthur Eubanks
1d64d9e07d Port -print-memderefs to NPM
There is lots of code duplication, but hopefully it won't matter soon.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D91683
2020-11-23 11:56:22 -08:00
Arthur Eubanks
c58b256afe [test] Pin memory-dereferenceable.ll to legacy PM
-print-memderefs is only used for one test and hasn't been touched in a while.
2020-11-23 11:56:17 -08:00
Matt Arsenault
f8cfaf8c10 OpaquePtr: Bulk update tests to use typed sret 2020-11-20 17:58:26 -05:00