#
f49ca52b |
| 29-May-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] See through op.with.overflow intrinsics (re-apply)
Summary: This change teaches SCEV to see reduce `(extractvalue 0 (op.with.overflow X Y))` into `op X Y` (with a no-wrap tag if possible).
T
[SCEV] See through op.with.overflow intrinsics (re-apply)
Summary: This change teaches SCEV to see reduce `(extractvalue 0 (op.with.overflow X Y))` into `op X Y` (with a no-wrap tag if possible).
This was first checked in at r265912 but reverted in r265950 because it exposed some issues around how SCEV handled post-inc add recurrences. Those issues have now been fixed.
Reviewers: atrick, regehr
Subscribers: mcrosier, mzolotukhin, llvm-commits
Differential Revision: http://reviews.llvm.org/D18684
llvm-svn: 271152
show more ...
|
#
7e4a6416 |
| 29-May-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Don't always add no-wrap flags to post-inc add recs
Fixes PR27315.
The post-inc version of an add recurrence needs to "follow the same rules" as a normal add or subtract expression. Otherwi
[SCEV] Don't always add no-wrap flags to post-inc add recs
Fixes PR27315.
The post-inc version of an add recurrence needs to "follow the same rules" as a normal add or subtract expression. Otherwise we miscompile programs like
``` int main() { int a = 0; unsigned a_u = 0; volatile long last_value; do { a_u += 3; last_value = (long) ((int) a_u); if (will_add_overflow(a, 3)) { // Leave, and don't actually do the increment, so no UB. printf("last_value = %ld\n", last_value); exit(0); } a += 3; } while (a != 46); return 0; } ```
This patch changes SCEV to put no-wrap flags on post-inc add recurrences only when the poison from a potential overflow will go ahead to cause undefined behavior.
To avoid regressing performance too much, I've assumed infinite loops without side effects is undefined behavior to prove poison<->UB equivalence in more cases. This isn't ideal, but is not new to LLVM as a whole, and far better than the situation I'm trying to fix.
llvm-svn: 271151
show more ...
|
#
eb4eccae |
| 25-May-2016 |
Oleg Ranevskyy <oranevskyy@accesssoftek.com> |
[SCEV] No-wrap flags are not propagated when folding "{S,+,X}+T ==> {S+T,+,X}"
Summary: **Description**
This makes `WidenIV::widenIVUse` (IndVarSimplify.cpp) fail to widen narrow IV uses in some ca
[SCEV] No-wrap flags are not propagated when folding "{S,+,X}+T ==> {S+T,+,X}"
Summary: **Description**
This makes `WidenIV::widenIVUse` (IndVarSimplify.cpp) fail to widen narrow IV uses in some cases. The latter affects IndVarSimplify which may not eliminate narrow IV's when there actually exists such a possibility, thereby producing ineffective code.
When `WidenIV::widenIVUse` gets a NarrowUse such as `{(-2 + %inc.lcssa),+,1}<nsw><%for.body3>`, it first tries to get a wide recurrence for it via the `getWideRecurrence` call. `getWideRecurrence` returns recurrence like this: `{(sext i32 (-2 + %inc.lcssa) to i64),+,1}<nsw><%for.body3>`.
Then a wide use operation is generated by `cloneIVUser`. The generated wide use is evaluated to `{(-2 + (sext i32 %inc.lcssa to i64))<nsw>,+,1}<nsw><%for.body3>`, which is different from the `getWideRecurrence` result. `cloneIVUser` sees the difference and returns nullptr.
This patch also fixes the broken LLVM tests by adding missing <nsw> entries introduced by the correction.
**Minimal reproducer:** ``` int foo(int a, int b, int c); int baz();
void bar() { int arr[20]; int i = 0;
for (i = 0; i < 4; ++i) arr[i] = baz();
for (; i < 20; ++i) arr[i] = foo(arr[i - 4], arr[i - 3], arr[i - 2]); } ```
**Clang command line:** ``` clang++ -mllvm -debug -S -emit-llvm -O3 --target=aarch64-linux-elf test.cpp -o test.ir ```
**Expected result:** The ` -mllvm -debug` log shows that all the IV's for the second `for` loop have been eliminated.
Reviewers: sanjoy
Subscribers: atrick, asl, aemerson, mzolotukhin, llvm-commits
Differential Revision: http://reviews.llvm.org/D20058
llvm-svn: 270695
show more ...
|
#
f5d40d53 |
| 17-May-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Be more aggressive in proving NUW
... for AddRec's in loops for which SCEV is unable to compute a max tripcount. This is the NUW variant of r269211 and fixes PR27691.
(Note: PR27691 is not
[SCEV] Be more aggressive in proving NUW
... for AddRec's in loops for which SCEV is unable to compute a max tripcount. This is the NUW variant of r269211 and fixes PR27691.
(Note: PR27691 is not a correct or stability bug, it was created to track a pending task).
llvm-svn: 269790
show more ...
|
#
24dbd2e7 |
| 13-May-2016 |
Silviu Baranga <silviu.baranga@arm.com> |
[scan-build] fix warnings emiited on LLVM Analysis code base
Fix "Logic error" warnings of the type "Called C++ object pointer is null" reported by Clang Static Analyzer on the following files:
lib
[scan-build] fix warnings emiited on LLVM Analysis code base
Fix "Logic error" warnings of the type "Called C++ object pointer is null" reported by Clang Static Analyzer on the following files:
lib/Analysis/ScalarEvolution.cpp, lib/Analysis/LoopInfo.cpp.
Patch by Apelete Seketeli!
llvm-svn: 269424
show more ...
|
#
787c2460 |
| 11-May-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Be more aggressive around proving no-wrap
... for AddRec's in loops for which SCEV is unable to compute a max tripcount. This is not a problem for "normal" loops[0] that don't have guards or
[SCEV] Be more aggressive around proving no-wrap
... for AddRec's in loops for which SCEV is unable to compute a max tripcount. This is not a problem for "normal" loops[0] that don't have guards or assumes, but helps in cases where we have guards or assumes in the loop that can be used to constrain incoming values over the backedge.
This partially fixes PR27691 (we still don't handle the NUW case).
[0]: for "normal" loops, in the cases where we'd be able to prove no-wrap via isKnownPredicate, we'd also be able to compute a max tripcount.
llvm-svn: 269211
show more ...
|
#
2512d0c8 |
| 10-May-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Use guards to prove predicates
We can use calls to @llvm.experimental.guard to prove predicates, relying on the fact that in all locations domianted by a call to @llvm.experimental.guard the
[SCEV] Use guards to prove predicates
We can use calls to @llvm.experimental.guard to prove predicates, relying on the fact that in all locations domianted by a call to @llvm.experimental.guard the predicate it is guarding is known to be true.
llvm-svn: 268997
show more ...
|
#
013a4ac4 |
| 03-May-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Tweak the output format and content of -analyze
In the "LoopDispositions:" section:
- Instead of printing out a list, print out a "dictionary" to make it obvious by inspection which disp
[SCEV] Tweak the output format and content of -analyze
In the "LoopDispositions:" section:
- Instead of printing out a list, print out a "dictionary" to make it obvious by inspection which disposition is for which loop. This is just a cosmetic change.
- Print dispositions for parent _and_ sibling loops. I will use this to write a test case.
llvm-svn: 268405
show more ...
|
#
33ae13d3 |
| 01-May-2016 |
Simon Pilgrim <llvm-dev@redking.me.uk> |
Fixed MSVC 'not all control paths return a value' warning
llvm-svn: 268198
|
#
f2f00fb1 |
| 01-May-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] When printing via -analysis, dump loop disposition
There are currently some bugs in tree around SCEV caching an incorrect loop disposition. Printing out loop dispositions will let us write w
[SCEV] When printing via -analysis, dump loop disposition
There are currently some bugs in tree around SCEV caching an incorrect loop disposition. Printing out loop dispositions will let us write whitebox tests as those are fixed.
The dispositions are printed as a list in "inside out" order, i.e. innermost loop first.
llvm-svn: 268177
show more ...
|
#
0da99375 |
| 29-Apr-2016 |
Filipe Cabecinhas <me@filcab.net> |
Unify XDEBUG and EXPENSIVE_CHECKS (into the latter), and add an option to the cmake build to enable them.
Summary: Historically, we had a switch in the Makefiles for turning on "expensive checks". T
Unify XDEBUG and EXPENSIVE_CHECKS (into the latter), and add an option to the cmake build to enable them.
Summary: Historically, we had a switch in the Makefiles for turning on "expensive checks". This has never been ported to the cmake build, but the (dead-ish) code is still around.
This will also make it easier to turn it on in buildbots.
Reviewers: chandlerc
Subscribers: jyknight, mzolotukhin, RKSimon, gberry, llvm-commits
Differential Revision: http://reviews.llvm.org/D19723
llvm-svn: 268050
show more ...
|
#
efdeb45f |
| 22-Apr-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Extract out a `isSCEVExprNeverPoison` helper; NFCI
Summary: Also adds a small comment blurb on control flow + no-wrap flags, since that question came up a few days back on llvm-dev.
Reviewer
[SCEV] Extract out a `isSCEVExprNeverPoison` helper; NFCI
Summary: Also adds a small comment blurb on control flow + no-wrap flags, since that question came up a few days back on llvm-dev.
Reviewers: bjarke.roune, broune
Subscribers: sanjoy, mcrosier, llvm-commits, mzolotukhin
Differential Revision: http://reviews.llvm.org/D19209
llvm-svn: 267110
show more ...
|
#
b77365b5 |
| 14-Apr-2016 |
Silviu Baranga <silviu.baranga@arm.com> |
[SCEV][LAA] Add tests for SCEV expression transformations performed during LAA
Summary: Add a print method to Predicated Scalar Evolution which prints all interesting transformations done by PSE.
L
[SCEV][LAA] Add tests for SCEV expression transformations performed during LAA
Summary: Add a print method to Predicated Scalar Evolution which prints all interesting transformations done by PSE.
Loop Access Analysis will now print this as part of the analysis output. We now use this to check the exact expression transformations that were done by PSE in LAA.
The additional checking also acts as white-box testing for the getAsAddRec method.
Reviewers: anemet, sanjoy
Subscribers: sanjoy, mzolotukhin, llvm-commits
Differential Revision: http://reviews.llvm.org/D18792
llvm-svn: 266334
show more ...
|
#
e48e3937 |
| 12-Apr-2016 |
Jeroen Ketema <j.ketema@imperial.ac.uk> |
Add space between words in verify-scev-maps option help message
llvm-svn: 266149
|
#
f9d88e65 |
| 11-Apr-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
This reverts commit r265913 and r265912
See PR27315
r265913: "[IndVars] Eliminate op.with.overflow when possible"
r265912: "[SCEV] See through op.with.overflow intrinsics" llvm-svn: 265950
|
#
3c529a40 |
| 10-Apr-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] See through op.with.overflow intrinsics
Summary: This change teaches SCEV to see reduce `(extractvalue 0 (op.with.overflow X Y))` into `op X Y` (with a no-wrap tag if possible).
Reviewers: a
[SCEV] See through op.with.overflow intrinsics
Summary: This change teaches SCEV to see reduce `(extractvalue 0 (op.with.overflow X Y))` into `op X Y` (with a no-wrap tag if possible).
Reviewers: atrick, regehr
Subscribers: mcrosier, mzolotukhin, llvm-commits
Differential Revision: http://reviews.llvm.org/D18684
llvm-svn: 265912
show more ...
|
#
6f444dfd |
| 08-Apr-2016 |
Silviu Baranga <silviu.baranga@arm.com> |
Re-commit [SCEV] Introduce a guarded backedge taken count and use it in LAA and LV
This re-commits r265535 which was reverted in r265541 because it broke the windows bots. The problem was that we ha
Re-commit [SCEV] Introduce a guarded backedge taken count and use it in LAA and LV
This re-commits r265535 which was reverted in r265541 because it broke the windows bots. The problem was that we had a PointerIntPair which took a pointer to a struct allocated with new. The problem was that new doesn't provide sufficient alignment guarantees. This pattern was already present before r265535 and it just happened to work. To fix this, we now separate the PointerToIntPair from the ExitNotTakenInfo struct into a pointer and a bool.
Original commit message:
Summary: When the backedge taken codition is computed from an icmp, SCEV can deduce the backedge taken count only if one of the sides of the icmp is an AddRecExpr. However, due to sign/zero extensions, we sometimes end up with something that is not an AddRecExpr.
However, we can use SCEV predicates to produce a 'guarded' expression. This change adds a method to SCEV to get this expression, and the SCEV predicate associated with it.
In HowManyGreaterThans and HowManyLessThans we will now add a SCEV predicate associated with the guarded backedge taken count when the analyzed SCEV expression is not an AddRecExpr. Note that we only do this as an alternative to returning a 'CouldNotCompute'.
We use new feature in Loop Access Analysis and LoopVectorize to analyze and transform more loops.
Reviewers: anemet, mzolotukhin, hfinkel, sanjoy
Subscribers: flyingforyou, mcrosier, atrick, mssimpso, sanjoy, mzolotukhin, llvm-commits
Differential Revision: http://reviews.llvm.org/D17201
llvm-svn: 265786
show more ...
|
#
5ce32728 |
| 08-Apr-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
Don't IPO over functions that can be de-refined
Summary: Fixes PR26774.
If you're aware of the issue, feel free to skip the "Motivation" section and jump directly to "This patch".
Motivation:
I d
Don't IPO over functions that can be de-refined
Summary: Fixes PR26774.
If you're aware of the issue, feel free to skip the "Motivation" section and jump directly to "This patch".
Motivation:
I define "refinement" as discarding behaviors from a program that the optimizer has license to discard. So transforming:
``` void f(unsigned x) { unsigned t = 5 / x; (void)t; } ```
to
``` void f(unsigned x) { } ```
is refinement, since the behavior went from "if x == 0 then undefined else nothing" to "nothing" (the optimizer has license to discard undefined behavior).
Refinement is a fundamental aspect of many mid-level optimizations done by LLVM. For instance, transforming `x == (x + 1)` to `false` also involves refinement since the expression's value went from "if x is `undef` then { `true` or `false` } else { `false` }" to "`false`" (by definition, the optimizer has license to fold `undef` to any non-`undef` value).
Unfortunately, refinement implies that the optimizer cannot assume that the implementation of a function it can see has all of the behavior an unoptimized or a differently optimized version of the same function can have. This is a problem for functions with comdat linkage, where a function can be replaced by an unoptimized or a differently optimized version of the same source level function.
For instance, FunctionAttrs cannot assume a comdat function is actually `readnone` even if it does not have any loads or stores in it; since there may have been loads and stores in the "original function" that were refined out in the currently visible variant, and at the link step the linker may in fact choose an implementation with a load or a store. As an example, consider a function that does two atomic loads from the same memory location, and writes to memory only if the two values are not equal. The optimizer is allowed to refine this function by first CSE'ing the two loads, and the folding the comparision to always report that the two values are equal. Such a refined variant will look like it is `readonly`. However, the unoptimized version of the function can still write to memory (since the two loads //can// result in different values), and selecting the unoptimized version at link time will retroactively invalidate transforms we may have done under the assumption that the function does not write to memory.
Note: this is not just a problem with atomics or with linking differently optimized object files. See PR26774 for more realistic examples that involved neither.
This patch:
This change introduces a new set of linkage types, predicated as `GlobalValue::mayBeDerefined` that returns true if the linkage type allows a function to be replaced by a differently optimized variant at link time. It then changes a set of IPO passes to bail out if they see such a function.
Reviewers: chandlerc, hfinkel, dexonsmith, joker.eph, rnk
Subscribers: mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18634
llvm-svn: 265762
show more ...
|
#
a393baf1 |
| 06-Apr-2016 |
Silviu Baranga <silviu.baranga@arm.com> |
Revert r265535 until we know how we can fix the bots
llvm-svn: 265541
|
#
72b4a4a3 |
| 06-Apr-2016 |
Silviu Baranga <silviu.baranga@arm.com> |
[SCEV] Introduce a guarded backedge taken count and use it in LAA and LV
Summary: When the backedge taken codition is computed from an icmp, SCEV can deduce the backedge taken count only if one of t
[SCEV] Introduce a guarded backedge taken count and use it in LAA and LV
Summary: When the backedge taken codition is computed from an icmp, SCEV can deduce the backedge taken count only if one of the sides of the icmp is an AddRecExpr. However, due to sign/zero extensions, we sometimes end up with something that is not an AddRecExpr.
However, we can use SCEV predicates to produce a 'guarded' expression. This change adds a method to SCEV to get this expression, and the SCEV predicate associated with it.
In HowManyGreaterThans and HowManyLessThans we will now add a SCEV predicate associated with the guarded backedge taken count when the analyzed SCEV expression is not an AddRecExpr. Note that we only do this as an alternative to returning a 'CouldNotCompute'.
We use new feature in Loop Access Analysis and LoopVectorize to analyze and transform more loops.
Reviewers: anemet, mzolotukhin, hfinkel, sanjoy
Subscribers: flyingforyou, mcrosier, atrick, mssimpso, sanjoy, mzolotukhin, llvm-commits
Differential Revision: http://reviews.llvm.org/D17201
llvm-svn: 265535
show more ...
|
#
e12c0e51 |
| 31-Mar-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Track NoWrap properties using MatchBinaryOp, NFC
This way once we teach MatchBinaryOp to map more things into arithmetic, the non-wrapping add recurrence construction would understand it too.
[SCEV] Track NoWrap properties using MatchBinaryOp, NFC
This way once we teach MatchBinaryOp to map more things into arithmetic, the non-wrapping add recurrence construction would understand it too. Right now MatchBinaryOp still only understands arithmetic, so this is solely a code-reorganization change.
llvm-svn: 264994
show more ...
|
#
118d919a |
| 31-Mar-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] NFC code motion to simplify later change
llvm-svn: 264993
|
#
2381fcd5 |
| 29-Mar-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Extract out a MatchBinaryOp; NFCI
MatchBinaryOp abstracts out the IR instructions from the operations they represent. While this change is NFC, we will use this factoring later to map things
[SCEV] Extract out a MatchBinaryOp; NFCI
MatchBinaryOp abstracts out the IR instructions from the operations they represent. While this change is NFC, we will use this factoring later to map things like `(extractvalue 0 (sadd.with.overflow X Y))` to `(add X Y)`.
llvm-svn: 264747
show more ...
|
#
260ad4dd |
| 29-Mar-2016 |
Sanjoy Das <sanjoy@playingwithpointers.com> |
[SCEV] Use Operator::getOpcode instead of manual dispatch; NFC
llvm-svn: 264746
|
#
d68ed854 |
| 23-Mar-2016 |
Silviu Baranga <silviu.baranga@arm.com> |
[SCEV] Change the SCEV Predicates interfaces for conversion to AddRecExpr to return SCEVAddRecExpr* instead of SCEV*
Summary: This changes the conversion functions from SCEV * to SCEVAddRecExpr from
[SCEV] Change the SCEV Predicates interfaces for conversion to AddRecExpr to return SCEVAddRecExpr* instead of SCEV*
Summary: This changes the conversion functions from SCEV * to SCEVAddRecExpr from ScalarEvolution and PredicatedScalarEvolution to return a SCEVAddRecExpr* instead of a SCEV* (which removes the need of most clients to do a dyn_cast right after calling these functions).
We also don't add new predicates if the transformation was not successful.
This is not entirely a NFC (as it can theoretically remove some predicates from LAA when we have an unknown dependece), but I couldn't find an obvious regression test for it.
Reviewers: sanjoy
Subscribers: sanjoy, mzolotukhin, llvm-commits
Differential Revision: http://reviews.llvm.org/D18368
llvm-svn: 264161
show more ...
|