OSDN Git Service

Simplify recursive launder.invariant.group and strip
authorPiotr Padlewski <piotr.padlewski@gmail.com>
Thu, 12 Jul 2018 23:55:20 +0000 (23:55 +0000)
committerPiotr Padlewski <piotr.padlewski@gmail.com>
Thu, 12 Jul 2018 23:55:20 +0000 (23:55 +0000)
commit674f0a117445cc5c1c8fd0ed51ff2377197ede1f
tree767ba2857ab191b5445a0ea5cdb9df77accef740
parentfda9d387d8ff911b12538646d277c3dc4c8197ca
Simplify recursive launder.invariant.group and strip

Summary:
This patch is crucial for proving equality laundered/stripped
pointers. eg:

  bool foo(A *a) {
    return a == std::launder(a);
  }

Clang with -fstrict-vtable-pointers will emit something like:

    define dso_local zeroext i1 @_Z3fooP1A(%struct.A* %a) {
    entry:
      %c = bitcast %struct.A* %a to i8*
      %call = tail call i8* @llvm.launder.invariant.group.p0i8(i8* %c)
      %0 = bitcast %struct.A* %a to i8*
      %1 = tail call i8* @llvm.strip.invariant.group.p0i8(i8* %0)
      %2 = tail call i8* @llvm.strip.invariant.group.p0i8(i8* %call)
      %cmp = icmp eq i8* %1, %2
      ret i1 %cmp
    }

and because %2 can be replaced with @llvm.strip.invariant.group(%0)
and that %2 and %1 will produce the same value (because strip is readnone)
we can replace compare with true.

Reviewers: rsmith, hfinkel, majnemer, amharc, kuhar

Subscribers: llvm-commits, hiraditya

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336963 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Analysis/ValueTracking/invariant.group.ll
test/Transforms/InstCombine/invariant.group.ll