[PATCH] D99240: [ConstantFolding] Look through local aliases when simplify GEPs

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 25 13:19:18 PDT 2021


aeubanks added a comment.

The (relevant part of the) code in the description after -O2 is:

  @global = private unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* bitcast (%struct.wibble* @global.1 to i8*), i8* bitcast (i32 (%struct.bar*)* @spam.12 to i8*), i8* bitcast (i8* (%struct.bar*, i32)* @blam to i8*)] }, comdat($"??_7B@?A0x8E5408E2@@6B@")
  
  @alias = internal unnamed_addr alias i8*, getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @global, i32 0, i32 0, i32 1)
  
  define dso_local i32 @foo() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @spam to i8*) {
  bb:
    %tmp = tail call noalias nonnull dereferenceable(8) i8* @"??2 at YAPEAX_K@Z"(i64 8) #5, !noalias !8
    %tmp1 = bitcast i8* %tmp to %struct.bar*
    %tmp2 = getelementptr inbounds %struct.bar, %struct.bar* %tmp1, i64 0, i32 0, i32 0
    store i32 (...)** bitcast (i8** @alias to i32 (...)**), i32 (...)*** %tmp2, align 8, !tbaa !11, !noalias !8
    %tmp3 = getelementptr %struct.bar, %struct.bar* %tmp1, i64 0, i32 0
    %tmp4 = load i8* (%struct.eggs*, i32)*, i8* (%struct.eggs*, i32)** bitcast (i8** getelementptr inbounds (i8*, i8** @alias, i64 1) to i8* (%struct.eggs*, i32)**), align 16
    %tmp5 = tail call i8* %tmp4(%struct.eggs* nonnull dereferenceable(8) %tmp3, i32 1) #6
    ret i32 41
  }

`%tmp4`'s operand gets simplified to the proper function pointer entry in `@global` with this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99240



More information about the llvm-commits mailing list