1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00
Go to file
Roman Lebedev ca7b7a7578 [InstSimplify] simplifyUnsignedRangeCheck(): if we know that X != 0, handle more cases (PR43246)
Summary:
This is motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.

In this particular case, given
```
char* test(char& base, unsigned long offset) {
  return &base + offset;
}
```
it will end up producing something like
https://godbolt.org/z/LK5-iH
which after optimizations reduces down to roughly
```
define i1 @t0(i8* nonnull %base, i64 %offset) {
  %base_int = ptrtoint i8* %base to i64
  %adjusted = add i64 %base_int, %offset
  %non_null_after_adjustment = icmp ne i64 %adjusted, 0
  %no_overflow_during_adjustment = icmp uge i64 %adjusted, %base_int
  %res = and i1 %non_null_after_adjustment, %no_overflow_during_adjustment
  ret i1 %res
}
```
Without D67122 there was no `%non_null_after_adjustment`,
and in this particular case we can get rid of the overhead:

Here we add some offset to a non-null pointer,
and check that the result does not overflow and is not a null pointer.
But since the base pointer is already non-null, and we check for overflow,
that overflow check will already catch the null pointer,
so the separate null check is redundant and can be dropped.

Alive proofs:
https://rise4fun.com/Alive/WRzq

There are more patterns of "unsigned-add-with-overflow", they are not handled here,
but this is the main pattern, that we currently consider canonical,
so it makes sense to handle it.

https://bugs.llvm.org/show_bug.cgi?id=43246

Reviewers: spatel, nikic, vsk

Reviewed By: spatel

Subscribers: hiraditya, llvm-commits, reames

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67332

llvm-svn: 371349
2019-09-08 20:14:15 +00:00
benchmarks
bindings Bump llvm-go to C++14 2019-08-15 10:55:25 +00:00
cmake [CMake] LLVM_COMPILE_FLAGS also applies to C files 2019-09-06 07:12:36 +00:00
docs [Intrinsic] Add the llvm.umul.fix.sat intrinsic 2019-09-07 12:16:14 +00:00
examples [ORCv2] - New Speculate Query Implementation 2019-08-27 18:23:36 +00:00
include [NFC] Make the describeLoadedValue() hook return machine operand objects 2019-09-08 14:05:10 +00:00
lib [InstSimplify] simplifyUnsignedRangeCheck(): if we know that X != 0, handle more cases (PR43246) 2019-09-08 20:14:15 +00:00
projects
resources
runtimes
test [InstSimplify] simplifyUnsignedRangeCheck(): if we know that X != 0, handle more cases (PR43246) 2019-09-08 20:14:15 +00:00
tools [llvm-nm] - Fix a bug and unbreak ASan BB. 2019-09-07 19:45:27 +00:00
unittests Change TargetLibraryInfo analysis passes to always require Function 2019-09-07 03:09:36 +00:00
utils [git-llvm] Do not reinvent @{upstream} 2019-09-07 06:44:52 +00:00
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt Revert Autogenerate the shebang lines for tools/opt-viewer 2019-08-27 18:31:29 +00:00
CODE_OWNERS.TXT
configure
CREDITS.TXT
LICENSE.TXT
llvm.spec.in
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.