[PATCH] D67849: [InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 11:02:24 PDT 2019
lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, xbolva00, nikic.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
This is again motivated by D67122 <https://reviews.llvm.org/D67122> sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
https://rise4fun.com/Alive/ALap
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67849
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/result-of-add-of-negative-is-non-zero-and-no-underflow.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67849.221069.patch
Type: text/x-patch
Size: 9604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190920/3caa765c/attachment.bin>
More information about the llvm-commits
mailing list