[PATCH] D97122: [SCEV] Improve handling of pointer compares involving subtractions (WIP).
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 20 11:13:16 PST 2021
fhahn created this revision.
fhahn added reviewers: reames, mkazantsev, sanjoy.google, nikic.
Herald added a subscriber: hiraditya.
fhahn requested review of this revision.
Herald added a project: LLVM.
WIP as I still need to do further testing and re-collecting &
applying the loop guards every time can be quite expensive in terms of
compile time. But I thought it would be good to share early, in case I
missed anything.
This patch improves handling of pointer comparisons involving
subtractions, by using knowledge that the involved variables are != 0
and signed positive.
It uses applyLoopGuards to add != 0 info to the involved expressions (by
re-writing them as umax expression. It also adds a new fold to move zext
into umax expressions and to move udiv expression inside subtraction, if
the operands guarantee a positive result.
The motivating code for this is eliminating range checks for code
like below from PR48965.
#include <assert.h>
void foo(const int *y, unsigned y_len) {
const int *y_end = y + y_len;
unsigned c = 0;
for (const int *y_iter = y; y_iter != y_end; y_iter++, c++) {
assert(c < y_len);
}
assert(c == y_len);
}
Proof for zext/umax fold: https://alive2.llvm.org/ce/z/t75T53
Proof for getUDivExpr extension:a https://alive2.llvm.org/ce/z/H_G2Q0
Proof for isKnownPredicateSubIdiom: https://alive2.llvm.org/ce/z/Gfe8mS
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97122
Files:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/test/Transforms/IndVarSimplify/simplify-pointer-arithmetic.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97122.325222.patch
Type: text/x-patch
Size: 9026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210220/65fcfa7d/attachment.bin>
More information about the llvm-commits
mailing list