[Loads] Add canReplacePointersIfEqual helper.
authorFlorian Hahn <flo@fhahn.com>
Tue, 1 Sep 2020 19:54:12 +0000 (20:54 +0100)
committerFlorian Hahn <flo@fhahn.com>
Tue, 1 Sep 2020 19:57:41 +0000 (20:57 +0100)
commit0d966ae4b2ac0344e15888d0f0a81c322e3d6dd2
treed181722dd290880223ed31980ed3d4b81c48d8d0
parent7139736261e047e9cca030e2ee5912bf2a16f816
[Loads] Add canReplacePointersIfEqual helper.

This patch adds an initial, incomeplete and unsound implementation of
canReplacePointersIfEqual to check if a pointer value A can be replaced
by another pointer value B, that are deemed to be equivalent through
some means (e.g. information from conditions).

Note that is in general not sound to blindly replace pointers based on
equality, for example if they are based on different underlying objects.

LLVM's memory model is not completely settled as of now; see
https://bugs.llvm.org/show_bug.cgi?id=34548 for a more detailed
discussion.

The initial version of canReplacePointersIfEqual only rejects a very
specific case: replacing a pointer with a constant expression that is
not dereferenceable. Such a replacement is problematic and can be
restricted relatively easily without impacting most code. Using it to
limit replacements in GVN/SCCP/CVP only results in small differences in
7 programs out of MultiSource/SPEC2000/SPEC2006 on X86 with -O3 -flto.

This patch is supposed to be an initial step to improve the current
situation and the helper should be made stricter in the future. But this
will require careful analysis of the impact on performance.

Reviewed By: aqjune

Differential Revision: https://reviews.llvm.org/D85524
llvm/include/llvm/Analysis/Loads.h
llvm/lib/Analysis/Loads.cpp
llvm/unittests/Analysis/LoadsTest.cpp