[PATCH] D101103: [InstSimplify] Treat invariant group insts as bitcasts for load operands

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 27 10:24:09 PDT 2021


aeubanks added a comment.

In D101103#2718965 <https://reviews.llvm.org/D101103#2718965>, @Prazek wrote:

> Out of curiosity: have you seen this pattern happening in the wild with -fstrict-vtable-pointers?

Yes, it was causing a major size regression in one specific file (with rtti). I've managed to reduce it down to

  struct A {
    int i;
    virtual void f();
    A(): i(4) {}
  };
  
  const A g;
  
  int foo() {
    const A* a = &g;
    return a->i;
  }

`$ ./build/rel/bin/clang++ /tmp/a.cc -o - -S -emit-llvm -O2 -fstrict-vtable-pointers`

  %struct.A = type <{ i32 (...)**, i32, [4 x i8] }>
  
  @_ZL1g = internal constant %struct.A <{ i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 4, [4 x i8] zeroinitializer }>, align 8
  @_ZTV1A = external dso_local unnamed_addr constant { [3 x i8*] }, align 8
  @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
  
  ; Function Attrs: nofree nosync nounwind readnone uwtable willreturn mustprogress
  define dso_local i32 @_Z8hahahahav() local_unnamed_addr #0 {
  entry:
    %0 = tail call i8* @llvm.strip.invariant.group.p0i8(i8* bitcast (%struct.A* @_ZL1g to i8*))
    %i = getelementptr inbounds i8, i8* %0, i64 8
    %1 = bitcast i8* %i to i32*
    %2 = load i32, i32* %1, align 8, !tbaa !6
    ret i32 %2
  }

`$ ./build/rel/bin/clang++ /tmp/a.cc -o - -S -emit-llvm -O2`

  ; Function Attrs: nofree norecurse nosync nounwind readnone uwtable willreturn mustprogress
  define dso_local i32 @_Z8hahahahav() local_unnamed_addr #0 {
  entry:
    ret i32 4
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101103/new/

https://reviews.llvm.org/D101103



More information about the llvm-commits mailing list