[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-20 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG304027206c88: [ThinLTO] Support aliased GlobalIFunc 
(authored by SchrodingerZhu, committed by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D129009?vs=446277=446279#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/ThinLTO/X86/alias-ifunc.ll

Index: llvm/test/ThinLTO/X86/alias-ifunc.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/alias-ifunc.ll
@@ -0,0 +1,57 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL
+
+; CHECK-SYMBOL: i bar
+; CHECK-SYMBOL: i baz
+; CHECK-SYMBOL: i foo
+; CHECK-SYMBOL: t foo_resolver
+; CHECK-SYMBOL: i grault
+; CHECK-SYMBOL: i quuz
+; CHECK-SYMBOL: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER:  (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+; CHECK-BAR:  (name: "bar"
+; CHECK-BAR-NOT:  summaries: (
+; CHECK-BAR-SAME: ; guid = {{[0-9]+}}
+@bar = alias i32 (i32), ptr @foo
+
+; CHECK-BAZ:  (name: "baz"
+; CHECK-BAZ-NOT:  summaries: (
+; CHECK-BAZ-SAME: ; guid = {{[0-9]+}}
+@baz = weak alias i32 (i32), ptr @foo
+
+; CHECK-QUX:  (name: "qux"
+; CHECK-QUX-NOT:  summaries: (
+; CHECK-QUX-SAME: ; guid = {{[0-9]+}}
+@qux = alias i32 (i32), ptr @bar
+
+; CHECK-QUUX:  (name: "quux"
+; CHECK-QUUX-SAME: live: 1
+@quux = internal alias i32 (i32)* (), ptr @foo_resolver
+@quuz = internal ifunc i32 (i32), ptr @quux
+
+; CHECK-CORGE:  (name: "corge"
+; CHECK-CORGE-NOT:  summaries: (
+; CHECK-CORGE-SAME: ; guid = {{[0-9]+}}
+@corge = internal alias i32 (i32), ptr @quuz
+
+; CHECK-GRAULT:  (name: "grault"
+; CHECK-GRAULT-NOT:  summaries: (
+; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}}
+@grault = alias i32 (i32), ptr @corge
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // Ifuncs and ifunc alias does not have summary.
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It may be the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa() ||
+(isa() &&
+ isa(cast()->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias  : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 446277.
MaskRay added a comment.

Add blank lines
remove trailing whitespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/ThinLTO/X86/alias-ifunc.ll

Index: llvm/test/ThinLTO/X86/alias-ifunc.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/alias-ifunc.ll
@@ -0,0 +1,57 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL
+
+; CHECK-SYMBOL: i bar
+; CHECK-SYMBOL: i baz
+; CHECK-SYMBOL: i foo
+; CHECK-SYMBOL: t foo_resolver
+; CHECK-SYMBOL: i grault
+; CHECK-SYMBOL: i quuz
+; CHECK-SYMBOL: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER:  (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+; CHECK-BAR:  (name: "bar"
+; CHECK-BAR-NOT:  summaries: (
+; CHECK-BAR-SAME: ; guid = {{[0-9]+}}
+@bar = alias i32 (i32), ptr @foo
+
+; CHECK-BAZ:  (name: "baz"
+; CHECK-BAZ-NOT:  summaries: (
+; CHECK-BAZ-SAME: ; guid = {{[0-9]+}}
+@baz = weak alias i32 (i32), ptr @foo
+
+; CHECK-QUX:  (name: "qux"
+; CHECK-QUX-NOT:  summaries: (
+; CHECK-QUX-SAME: ; guid = {{[0-9]+}}
+@qux = alias i32 (i32), ptr @bar
+
+; CHECK-QUUX:  (name: "quux"
+; CHECK-QUUX-SAME: live: 1
+@quux = internal alias i32 (i32)* (), ptr @foo_resolver
+@quuz = internal ifunc i32 (i32), ptr @quux
+
+; CHECK-CORGE:  (name: "corge"
+; CHECK-CORGE-NOT:  summaries: (
+; CHECK-CORGE-SAME: ; guid = {{[0-9]+}}
+@corge = internal alias i32 (i32), ptr @quuz
+
+; CHECK-GRAULT:  (name: "grault"
+; CHECK-GRAULT-NOT:  summaries: (
+; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}}
+@grault = alias i32 (i32), ptr @corge
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // Ifuncs and ifunc alias does not have summary.
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It may be the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa() ||
+(isa() &&
+ isa(cast()->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias  : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -316,32 +316,38 @@
   return true;
 }
 
+template 
 static const GlobalObject *
-findBaseObject(const Constant *C, DenseSet ) {
-  if (auto *GO = 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D129009#3665664 , @SchrodingerZhu 
wrote:

> Hi, is there anything else I should do for this patch?

There is no. I am waiting a bit to collect more response. I'll do some testing 
and push this. Thanks for your contribution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-20 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu added a comment.

Hi, is there anything else I should do for this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-10 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 443536.
SchrodingerZhu added a comment.

This commit addresses issues mentioned in code reviews:

- change applyAlongResolverPath to use reference since the pointer is supposed 
to be non-null.
- update test format to align check rules under the same prefix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/ThinLTO/X86/alias-ifunc.ll

Index: llvm/test/ThinLTO/X86/alias-ifunc.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/alias-ifunc.ll
@@ -0,0 +1,51 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL
+; CHECK-SYMBOL: i bar
+; CHECK-SYMBOL: i baz
+; CHECK-SYMBOL: i foo
+; CHECK-SYMBOL: t foo_resolver
+; CHECK-SYMBOL: i grault
+; CHECK-SYMBOL: i quuz
+; CHECK-SYMBOL: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER:  (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+; CHECK-BAR:  (name: "bar"
+; CHECK-BAR-NOT:  summaries: ( 
+; CHECK-BAR-SAME: ; guid = {{[0-9]+}}
+@bar = alias i32 (i32), ptr @foo
+; CHECK-BAZ:  (name: "baz"
+; CHECK-BAZ-NOT:  summaries: ( 
+; CHECK-BAZ-SAME: ; guid = {{[0-9]+}}
+@baz = weak alias i32 (i32), ptr @foo
+; CHECK-QUX:  (name: "qux"
+; CHECK-QUX-NOT:  summaries: ( 
+; CHECK-QUX-SAME: ; guid = {{[0-9]+}}
+@qux = alias i32 (i32), ptr @bar
+; CHECK-QUUX:  (name: "quux"
+; CHECK-QUUX-SAME: live: 1
+@quux = internal alias i32 (i32)* (), ptr @foo_resolver
+@quuz = internal ifunc i32 (i32), ptr @quux
+; CHECK-CORGE:  (name: "corge"
+; CHECK-CORGE-NOT:  summaries: ( 
+; CHECK-CORGE-SAME: ; guid = {{[0-9]+}}
+@corge = internal alias i32 (i32), ptr @quuz
+; CHECK-GRAULT:  (name: "grault"
+; CHECK-GRAULT-NOT:  summaries: ( 
+; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}}
+@grault = alias i32 (i32), ptr @corge
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // Ifuncs and ifunc alias does not have summary.
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It may be the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa() ||
+(isa() &&
+ isa(cast()->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias  : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

  As https://github.com/llvm/llvm-project/issues/56290 indicates, when an ifunc 
is aliased in LTO, clang will attempt to create an alias summary; however, as 
ifunc is not included in the module summary, doing so will lead to problems.
  
  Fixes https://github.com/llvm/llvm-project/issues/56290

Don't repeat the link. You can use :

  Fixes https://github.com/llvm/llvm-project/issues/56290: when an ifunc ...




Comment at: llvm/include/llvm/IR/GlobalIFunc.h:102
+  /// aliases along the path.
+  void applyAlongResolverPath(function_ref Op) 
const;
 };

Prefer `const GlobalValue &` if not-nullable.



Comment at: llvm/test/ThinLTO/X86/alias-ifunc.ll:22
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER: (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1

For the same check prefix, align the content.

```
; CHECK-RESOLVER:  (name: "foo_resolver"
; CHECK-RESOLVER-SAME: live: 1



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-10 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 443503.
SchrodingerZhu marked 5 inline comments as done.
SchrodingerZhu added a comment.

This commit addresses problems mentioned in code reviews:

- Fix format and wording for comments
- Add more checks with llvm-dis
- Adjust code styles for function references, and auto inference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/ThinLTO/X86/alias-ifunc.ll

Index: llvm/test/ThinLTO/X86/alias-ifunc.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/alias-ifunc.ll
@@ -0,0 +1,51 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL
+; CHECK-SYMBOL: i bar
+; CHECK-SYMBOL: i baz
+; CHECK-SYMBOL: i foo
+; CHECK-SYMBOL: t foo_resolver
+; CHECK-SYMBOL: i grault
+; CHECK-SYMBOL: i quuz
+; CHECK-SYMBOL: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER: (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+; CHECK-BAR: (name: "bar"
+; CHECK-BAR-NOT: summaries: ( 
+; CHECK-BAR-SAME: ; guid = {{[0-9]+}}
+@bar = alias i32 (i32), ptr @foo
+; CHECK-BAZ: (name: "baz"
+; CHECK-BAZ-NOT: summaries: ( 
+; CHECK-BAZ-SAME: ; guid = {{[0-9]+}}
+@baz = weak alias i32 (i32), ptr @foo
+; CHECK-QUX: (name: "qux"
+; CHECK-QUX-NOT: summaries: ( 
+; CHECK-QUX-SAME: ; guid = {{[0-9]+}}
+@qux = alias i32 (i32), ptr @bar
+; CHECK-QUUX: (name: "quux"
+; CHECK-QUUX-SAME: live: 1
+@quux = internal alias i32 (i32)* (), ptr @foo_resolver
+@quuz = internal ifunc i32 (i32), ptr @quux
+; CHECK-CORGE: (name: "corge"
+; CHECK-CORGE-NOT: summaries: ( 
+; CHECK-CORGE-SAME: ; guid = {{[0-9]+}}
+@corge = internal alias i32 (i32), ptr @quuz
+; CHECK-GRAULT: (name: "grault"
+; CHECK-GRAULT-NOT: summaries: ( 
+; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}}
+@grault = alias i32 (i32), ptr @corge
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // Ifuncs and ifunc alias does not have summary.
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It may be the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa() ||
+(isa() &&
+ isa(cast()->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias  : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll:15
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+

Replace all these `xxx*` to `ptr` (opaque pointers). See recent clang's codegen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

OK, I think the approach is fine.




Comment at: llvm/include/llvm/IR/GlobalIFunc.h:97
+
+  /// Method to apply specific operation to all resolver-related values.
+  /// If resolver target is already a global object, then apply the operation 
to

Delete `Method to`



Comment at: llvm/include/llvm/IR/GlobalIFunc.h:99
+  /// If resolver target is already a global object, then apply the operation 
to
+  /// it directly. If target is an expr or an alias, evaluate it to its base
+  /// object and apply the operation for the base object and all aliases along

expr -> ConstantExpr



Comment at: llvm/include/llvm/IR/GlobalIFunc.h:103
+  void applyAlongResolverPath(
+  const std::function ) const;
 };

Use function_ref instead.



Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:652
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not

Delete the blank line and move the comment above `GlobalObject *Aliasee = 
A.getAliaseeObject();` (expand `auto`s which may hinder readability).



Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:821
+  for (const GlobalIFunc  : M.ifuncs()) {
+std::function Setter =
+[](const GlobalValue *GV) {

`I.applyAlongResolverPath([](const GlobalValue *GV) { ... })`



Comment at: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:4106
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.

// Skip ifunc and nameless functions which don't have an entry in the summary



Comment at: llvm/lib/IR/Globals.cpp:360
   DenseSet Aliases;
-  return findBaseObject(this, Aliases);
+  return findBaseObject(this, Aliases, [](...) {});
 }

Change `...` to `const GlobalValue *`



Comment at: llvm/lib/IR/Globals.cpp:553
   DenseSet Aliases;
-  return findBaseObject(getOperand(0), Aliases);
+  return findBaseObject(getOperand(0), Aliases, [](...) {});
 }

Change `...` to `const GlobalValue *`



Comment at: llvm/lib/IR/Globals.cpp:590
+void GlobalIFunc::applyAlongResolverPath(
+const std::function ) const {
+  DenseSet Aliases;

Use `function_ref` instead.



Comment at: llvm/lib/Transforms/IPO/FunctionImport.cpp:1155
+(isa() &&
+ isa(dyn_cast()->getAliaseeObject(
+  return true;

`s/dyn_cast/cast` if known to be of the type.

`cast().getAliaseeObject()`



Comment at: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp:39
+
+  // ifuncs and ifunc aliasee does not have summary
+  if (isa(SGV) ||





Comment at: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll:1
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r 
%t.bc,qux,px -r %t.bc,grault,px -o %t2

llvm/test/ThinLTO/X86/alias-ifunc is better.

I'll remove `-lto` from the filename since it conveys no additional information.

Additionally test `llvm-dis < %t.bc`

Test something like

```
^1 = gv: (name: "quux", summaries: (alias: (module: ^0, flags: (linkage: 
internal, visibility: default, notEligibleToImport: 0, live: 1, dsoLocal: 1, 
canAutoHide: 0), aliasee: ^6)))
^2 = ...   # have the line to test that there is no summary
^3 = ...
^6 = gv: (name: "foo_resolver", summaries: (function: (module: ^0, flags: 
(linkage: internal, visibility: default, notEligibleToImport: 0, live: 1, 
dsoLocal: 1, canAutoHide: 0), insts: 1))) 
```



Comment at: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll:31
+
+; no crash

Delete


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-07 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu added a comment.

First of all, I am really sorry about the noise and the misbehavior here. I 
have to admit that some of the changes here are because I am still in the way 
of getting familiar with the patch system. I apologize for being careless in 
the progress.

> I don't know how you added reviewers or whether you got upset after I clicked 
> "Request Changes".

I am very glad to recieve any review from you and any other member from the 
team! It is just that I saw you push some commits to the monorepo recently, so 
I thought that you were too busy to review the patch. Again, I am sorry for the 
confusion.

> I haven't taken a second deep look at this patch but the 
> applyAlongResolverPath change looks too intrusive to me. One previous version 
> seems more favorable to me.

Back to the patch itself, I made the changes because in the previous version, I 
assumed that, along the de-aliasing path to the `resolver` object, the 
immediate instance of `Constant*` need to be `GlobalObject` or `GlobalAlias`; 
but the `resolver` is stored as a `Constant *`, behind which, according to the 
implementation of `findBaseObject`, can also be instantiated as `Expr`.

I am looking forward to your suggestions, on the code and on how to follow the 
community conventions better!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I feel obliged to point out that the sheer number of updates is too large. 
Every update triggers an email to all reviewers and subscribers, so please be 
mindful. Personally I don't mind how many updates I receive, but others may do.
It's usually not too bad to have too many reviewers (having too few reviewers 
can be more of a problem at times).
I don't know how you added reviewers or whether you got upset after I clicked 
"Request Changes".

https://llvm.org/docs/CodeReview.html#lgtm-how-a-patch-is-accepted "Please also 
be mindful of weekends and major holidays."
July 4 is a federal holiday in the United States, so many folks may not be 
responsive during the long weekend.
(For my case I just finished my trip mode.)

I haven't taken a second deep look at this patch but the 
`applyAlongResolverPath` change looks too intrusive to me. One previous version 
seems more favorable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-05 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu added a comment.

@MaskRay PTAL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441906.
SchrodingerZhu added a comment.

typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll

Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,31 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+; CHECK: i grault
+; CHECK: i quuz
+; CHECK: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+@qux = alias i32 (i32), i32 (i32)* @bar
+
+@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver
+@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux
+@corge = internal alias i32 (i32), i32 (i32)* @quuz
+@grault = alias i32 (i32), i32 (i32)* @corge
+
+; no crash
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // ifuncs and ifunc aliasee does not have summary
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It maybe the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa() ||
+(isa() &&
+ isa(dyn_cast()->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias  : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -316,32 +316,38 @@
   return true;
 }
 
+template 
 static const GlobalObject *
-findBaseObject(const Constant *C, DenseSet ) {
-  if (auto *GO = dyn_cast(C))
+findBaseObject(const Constant *C, DenseSet ,
+   const Operation ) {
+  if (auto *GO = dyn_cast(C)) {
+Op(GO);
 return GO;
-  if (auto *GA = dyn_cast(C))
+  }
+  if (auto *GA = dyn_cast(C)) {
+Op(GA);
 if (Aliases.insert(GA).second)
-  return findBaseObject(GA->getOperand(0), Aliases);
+  return findBaseObject(GA->getOperand(0), Aliases, Op);
+  }
   if (auto *CE = dyn_cast(C)) {
 switch (CE->getOpcode()) {
 case Instruction::Add: {
-  auto *LHS = findBaseObject(CE->getOperand(0), Aliases);
-  auto *RHS = findBaseObject(CE->getOperand(1), Aliases);
+  auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
+  auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
   if (LHS && RHS)
 return nullptr;
   return LHS ? LHS : RHS;
 }
 case Instruction::Sub: {
-  if (findBaseObject(CE->getOperand(1), Aliases))
+  if (findBaseObject(CE->getOperand(1), Aliases, Op))
 return nullptr;
-  return findBaseObject(CE->getOperand(0), Aliases);
+  return 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441905.
SchrodingerZhu added a comment.

more clean ups for ifunc logic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll

Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,31 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+; CHECK: i grault
+; CHECK: i quuz
+; CHECK: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+@qux = alias i32 (i32), i32 (i32)* @bar
+
+@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver
+@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux
+@corge = internal alias i32 (i32), i32 (i32)* @quuz
+@grault = alias i32 (i32), i32 (i32)* @corge
+
+; no crash
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // ifuncs and ifunc aliasee does not have summary
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It maybe the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa() ||
+(isa() &&
+ isa(dyn_cast()->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias  : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -316,32 +316,38 @@
   return true;
 }
 
+template 
 static const GlobalObject *
-findBaseObject(const Constant *C, DenseSet ) {
-  if (auto *GO = dyn_cast(C))
+findBaseObject(const Constant *C, DenseSet ,
+   const Operation ) {
+  if (auto *GO = dyn_cast(C)) {
+Op(GO);
 return GO;
-  if (auto *GA = dyn_cast(C))
+  }
+  if (auto *GA = dyn_cast(C)) {
+Op(GA);
 if (Aliases.insert(GA).second)
-  return findBaseObject(GA->getOperand(0), Aliases);
+  return findBaseObject(GA->getOperand(0), Aliases, Op);
+  }
   if (auto *CE = dyn_cast(C)) {
 switch (CE->getOpcode()) {
 case Instruction::Add: {
-  auto *LHS = findBaseObject(CE->getOperand(0), Aliases);
-  auto *RHS = findBaseObject(CE->getOperand(1), Aliases);
+  auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
+  auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
   if (LHS && RHS)
 return nullptr;
   return LHS ? LHS : RHS;
 }
 case Instruction::Sub: {
-  if (findBaseObject(CE->getOperand(1), Aliases))
+  if (findBaseObject(CE->getOperand(1), Aliases, Op))
 return nullptr;
-  return findBaseObject(CE->getOperand(0), Aliases);
+  

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu marked an inline comment as done.
SchrodingerZhu added a comment.

ThinLTO with IFUNC is still


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441899.
SchrodingerZhu added a comment.

fix test arg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll

Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,31 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+; CHECK: i grault
+; CHECK: i quuz
+; CHECK: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+@qux = alias i32 (i32), i32 (i32)* @bar
+
+@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver
+@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux
+@corge = internal alias i32 (i32), i32 (i32)* @quuz
+@grault = alias i32 (i32), i32 (i32)* @corge
+
+; no crash
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -59,7 +59,13 @@
   // in this module.
   auto Summary = ImportIndex.findSummaryInModule(
   VI, SGV->getParent()->getModuleIdentifier());
-  assert(Summary && "Missing summary for global value when exporting");
+
+  // It maybe the case that SGV is on a chain of an ifunc, its alias and
+  // subsequent aliases. In this case, the summary for the value is not
+  // available.
+  if (!Summary)
+return false;
+
   auto Linkage = Summary->linkage();
   if (!GlobalValue::isLocalLinkage(Linkage)) {
 assert(!isNonRenamableLocal(*SGV) &&
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1169,10 +1169,13 @@
 // recorded in the index using the original name.
 // FIXME: This may not be needed once PR27866 is fixed.
 GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName));
-assert(GS != DefinedGlobals.end());
   }
 }
-return !GlobalValue::isLocalLinkage(GS->second->linkage());
+// It maybe the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+return GS == DefinedGlobals.end() ||
+   !GlobalValue::isLocalLinkage(GS->second->linkage());
   };
 
   // FIXME: See if we can just internalize directly here via linkage changes
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441898.
SchrodingerZhu added a comment.

fix test arg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll

Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,31 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r t.bc,foo,px -r t.bc,bar,px -r t.bc,baz,px -r t.bc,qux,px -r t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+; CHECK: i grault
+; CHECK: i quuz
+; CHECK: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+@qux = alias i32 (i32), i32 (i32)* @bar
+
+@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver
+@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux
+@corge = internal alias i32 (i32), i32 (i32)* @quuz
+@grault = alias i32 (i32), i32 (i32)* @corge
+
+; no crash
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -59,7 +59,13 @@
   // in this module.
   auto Summary = ImportIndex.findSummaryInModule(
   VI, SGV->getParent()->getModuleIdentifier());
-  assert(Summary && "Missing summary for global value when exporting");
+
+  // It maybe the case that SGV is on a chain of an ifunc, its alias and
+  // subsequent aliases. In this case, the summary for the value is not
+  // available.
+  if (!Summary)
+return false;
+
   auto Linkage = Summary->linkage();
   if (!GlobalValue::isLocalLinkage(Linkage)) {
 assert(!isNonRenamableLocal(*SGV) &&
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1169,10 +1169,13 @@
 // recorded in the index using the original name.
 // FIXME: This may not be needed once PR27866 is fixed.
 GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName));
-assert(GS != DefinedGlobals.end());
   }
 }
-return !GlobalValue::isLocalLinkage(GS->second->linkage());
+// It maybe the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+return GS == DefinedGlobals.end() ||
+   !GlobalValue::isLocalLinkage(GS->second->linkage());
   };
 
   // FIXME: See if we can just internalize directly here via linkage changes
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441897.
SchrodingerZhu added a comment.

enlarge test and fix accordingly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll

Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,31 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+; CHECK: i grault
+; CHECK: i quuz
+; CHECK: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+@qux = alias i32 (i32), i32 (i32)* @bar
+
+@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver
+@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux
+@corge = internal alias i32 (i32), i32 (i32)* @quuz
+@grault = alias i32 (i32), i32 (i32)* @corge
+
+; no crash
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -59,7 +59,13 @@
   // in this module.
   auto Summary = ImportIndex.findSummaryInModule(
   VI, SGV->getParent()->getModuleIdentifier());
-  assert(Summary && "Missing summary for global value when exporting");
+
+  // It maybe the case that SGV is on a chain of an ifunc, its alias and
+  // subsequent aliases. In this case, the summary for the value is not
+  // available.
+  if (!Summary)
+return false;
+
   auto Linkage = Summary->linkage();
   if (!GlobalValue::isLocalLinkage(Linkage)) {
 assert(!isNonRenamableLocal(*SGV) &&
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1169,10 +1169,13 @@
 // recorded in the index using the original name.
 // FIXME: This may not be needed once PR27866 is fixed.
 GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName));
-assert(GS != DefinedGlobals.end());
   }
 }
-return !GlobalValue::isLocalLinkage(GS->second->linkage());
+// It maybe the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+return GS == DefinedGlobals.end() ||
+   !GlobalValue::isLocalLinkage(GS->second->linkage());
   };
 
   // FIXME: See if we can just internalize directly here via linkage changes
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441895.
SchrodingerZhu added a comment.

fix typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll

Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -59,7 +59,13 @@
   // in this module.
   auto Summary = ImportIndex.findSummaryInModule(
   VI, SGV->getParent()->getModuleIdentifier());
-  assert(Summary && "Missing summary for global value when exporting");
+
+  // It maybe the case that SGV is on a chain of an ifunc, its alias and
+  // subsequent aliases. In this case, the summary for the value is not
+  // available.
+  if (!Summary)
+return false;
+
   auto Linkage = Summary->linkage();
   if (!GlobalValue::isLocalLinkage(Linkage)) {
 assert(!isNonRenamableLocal(*SGV) &&
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1169,10 +1169,13 @@
 // recorded in the index using the original name.
 // FIXME: This may not be needed once PR27866 is fixed.
 GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName));
-assert(GS != DefinedGlobals.end());
   }
 }
-return !GlobalValue::isLocalLinkage(GS->second->linkage());
+// It maybe the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+return GS == DefinedGlobals.end() ||
+   !GlobalValue::isLocalLinkage(GS->second->linkage());
   };
 
   // FIXME: See if we can just internalize directly here via linkage changes
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
@@ -811,6 +816,10 @@
   for (const GlobalAlias  : M.aliases())
 computeAliasSummary(Index, 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441894.
SchrodingerZhu added a comment.

fix more


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll

Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -59,7 +59,13 @@
   // in this module.
   auto Summary = ImportIndex.findSummaryInModule(
   VI, SGV->getParent()->getModuleIdentifier());
-  assert(Summary && "Missing summary for global value when exporting");
+
+  // It maybe the case that SGV is on a chain of an ifunc, its alias and
+  // subsequent aliases. In this case, the summary for the value is not
+  // available.
+  if (!Summary)
+return false;
+
   auto Linkage = Summary->linkage();
   if (!GlobalValue::isLocalLinkage(Linkage)) {
 assert(!isNonRenamableLocal(*SGV) &&
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1169,10 +1169,13 @@
 // recorded in the index using the original name.
 // FIXME: This may not be needed once PR27866 is fixed.
 GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName));
-assert(GS != DefinedGlobals.end());
   }
 }
-return !GlobalValue::isLocalLinkage(GS->second->linkage());
+// It maybe the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+return GS != DefinedGlobals.end() ||
+   !GlobalValue::isLocalLinkage(GS->second->linkage());
   };
 
   // FIXME: See if we can just internalize directly here via linkage changes
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
@@ -811,6 +816,10 @@
   for (const GlobalAlias  : M.aliases())
 computeAliasSummary(Index, 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441891.
SchrodingerZhu added a comment.

fix liveness of resolvers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o 
%t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,12 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It maybe the case that the symbol is aliasing an ifunc where
+// the summary is not available.
+if (isa() &&
+isa(dyn_cast()->getAliasee()))
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
@@ -811,6 +816,10 @@
   for (const GlobalAlias  : M.aliases())
 computeAliasSummary(Index, A, CantBePromoted);
 
+  // Iterate through ifuncs, set their resolvers all alive.
+  for (const GlobalIFunc  : M.ifuncs())
+Index.getGlobalValueSummary(*I.getResolverFunction())->setLive(true);
+
   for (auto *V : LocalsUsed) {
 auto *Summary = Index.getGlobalValueSummary(*V);
 assert(Summary && "Missing summary for global value");


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu added a comment.

The LTO problem is fixed but thinlto is not fully resolved:

   /home/schrodinger/Documents/llvm-project/llvm/cmake-build-debug/bin/clang 
test.c -o test -flto=thin -sha
  red -fuse-ld=lld
  IFunc resolver must be a definition
  ptr @f
  LLVM ERROR: Broken module found, compilation aborted!
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace.
   #0 0x559adcf4c647 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/home/schrodinger/Documents/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
   #1 0x559adcf4c85b PrintStackTraceSignalHandler(void*) 
/home/schrodinger/Documents/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
   #2 0x559adcf4abf3 llvm::sys::RunSignalHandlers() 
/home/schrodinger/Documents/llvm-project/llvm/lib/Support/Signals.cpp:103:5
   #3 0x559adcf4d071 SignalHandler(int) 
/home/schrodinger/Documents/llvm-project/llvm/lib/Support/Unix/Signals.inc:0:3
   #4 0x7f4a56705150 (/usr/lib/libc.so.6+0x42150)
   #5 0x7f4a567606db pthread_kill (/usr/lib/libc.so.6+0x9d6db)
   #6 0x7f4a567050a8 gsignal (/usr/lib/libc.so.6+0x420a8)
   #7 0x7f4a566eb535 abort (/usr/lib/libc.so.6+0x28535)
   #8 0x559adce51e34 llvm::report_fatal_error(llvm::Twine const&, bool) 
/home/schrodinger/Documents/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5
   #9 0x559adce51ca2 
/home/schrodinger/Documents/llvm-project/llvm/lib/Support/ErrorHandling.cpp:83:3
  #10 0x559ae2a64551 llvm::VerifierPass::run(llvm::Module&, 
llvm::AnalysisManager&) 
/home/schrodinger/Documents/llvm-project/llvm/lib/IR/Verifier.cpp:0:5
  #11 0x559ae006e757 llvm::detail::PassModel>::run(llvm::Module&, 
llvm::AnalysisManager&) 
/home/schrodinger/Documents/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:88:17
  #12 0x559ae2ac llvm::PassManager>::run(llvm::Module&, 
llvm::AnalysisManager&) 
/home/schrodinger/Documents/llvm-project/llvm/include/llvm/IR/PassManager.h:522:16
  #13 0x559ae0062e9f runNewPMPasses(llvm::lto::Config const&, 
llvm::Module&, llvm::TargetMachine*, unsigned int, bool, 
llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*) 
/home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:309:7
  #14 0x559ae00620f7 llvm::lto::opt(llvm::lto::Config const&, 
llvm::TargetMachine*, unsigned int, llvm::Module&, bool, 
llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*, 
std::vector> const&) 
/home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:336:11
  #15 0x559ae0064d1f llvm::lto::thinBackend(llvm::lto::Config const&, 
unsigned int, 
std::function>> (unsigned int)>, llvm::Module&, 
llvm::ModuleSummaryIndex const&, llvm::StringMap, std::equal_to, 
std::allocator>, llvm::MallocAllocator> const&, 
llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>*, 
std::vector> 
const&)::$_6::operator()(llvm::Module&, llvm::TargetMachine*, 
std::unique_ptr>) const 
/home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:554:13
  #16 0x559ae0064c2c llvm::lto::thinBackend(llvm::lto::Config const&, 
unsigned int, 
std::function>> (unsigned int)>, llvm::Module&, 
llvm::ModuleSummaryIndex const&, llvm::StringMap, std::equal_to, 
std::allocator>, llvm::MallocAllocator> const&, 
llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>*, 
std::vector> const&) 
/home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:630:3
  #17 0x559ae0031752 (anonymous 
namespace)::InProcessThinBackend::runThinLTOBackendThread(std::function>> (unsigned int)>, 
std::function>> (unsigned int)>> (unsigned int, 
llvm::StringRef)>, unsigned int, llvm::BitcodeModule, 
llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, 
std::allocator>> const&, llvm::DenseMap, 
llvm::detail::DenseMapPair> const&, 
llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>&)::'lambda'(std::function>> (unsigned 
int)>)::operator()(std::function>> (unsigned int)>) const 
/home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTO.cpp:1256:7
  #18 0x559ae00312df (anonymous 
namespace)::InProcessThinBackend::runThinLTOBackendThread(std::function>> (unsigned int)>, 
std::function>> (unsigned int)>> (unsigned int, 
llvm::StringRef)>, unsigned int, llvm::BitcodeModule, 
llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, 
std::allocator>> const&, llvm::DenseMap, 
llvm::detail::DenseMapPair> const&, 
llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>&) 
/home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTO.cpp:1272:7
  #19 0x559ae0030e86 (anonymous 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441887.
SchrodingerZhu added a comment.

- format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o 
%t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,12 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It maybe the case that the symbol is aliasing an ifunc where
+// the summary is not available.
+if (isa() &&
+isa(dyn_cast()->getAliasee()))
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441886.
SchrodingerZhu added a comment.

- stage
- stage
- fix lto


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o 
%t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,12 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue ) -> bool {
+// It maybe the case that the symbol is aliasing an ifunc where
+// the summary is not available.
+if (isa() &&
+ isa(dyn_cast()->getAliasee()))
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu added a comment.

@MaskRay unfortunately and fortunately, extending the test case to

  ; RUN: opt -module-summary -o %t.bc %s
  ; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,px -r %t.bc,baz,px -o 
%t2
  ; RUN: llvm-nm %t2.1 | FileCheck %s
  ; CHECK: i foo
  ; CHECK: t foo_resolver
  ; CHECK: T bar
  ; CHECK: W baz

gives me another crash at LTO stage:

   #0 0x56128a37edb9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1bb4db9)
   #1 0x56128a37ef6e SignalHandler(int) Signals.cpp:0:0
   #2 0x7f0ba5506150 (/usr/lib/libc.so.6+0x42150)
   #3 0x56128a6dcdd7 std::_Function_handler, 
llvm::detail::DenseMapPair> 
const&)::$_4>::_M_invoke(std::_Any_data const&, llvm::GlobalValue const&) 
FunctionImport.cpp:0:0
   #4 0x56128a7073fe 
llvm::InternalizePass::maybeInternalize(llvm::GlobalValue&, 
llvm::DenseMap, 
llvm::detail::DenseMapPair>&) 
(/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1f3d3fe)
   #5 0x56128a707990 
llvm::InternalizePass::internalizeModule(llvm::Module&, llvm::CallGraph*) 
(/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1f3d990)
   #6 0x56128a6d9df0 llvm::thinLTOInternalizeModule(llvm::Module&, 
llvm::DenseMap, llvm::detail::DenseMapPair> const&) 
(/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1f0fdf0)
   #7 0x56128a181dba llvm::lto::thinBackend(llvm::lto::Config const&, 
unsigned int, 
std::function>> (unsigned int)>, llvm::Module&, 
llvm::ModuleSummaryIndex const&, llvm::StringMap, std::equal_to, 
std::allocator>, llvm::MallocAllocator> const&, 
llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>*, 
std::vector> const&) 
(/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x19b7dba)
   #8 0x56128a17d8b0 (anonymous 
namespace)::InProcessThinBackend::runThinLTOBackendThread(std::function>> (unsigned int)>, 
std::function>> (unsigned int)>> (unsigned int, 
llvm::StringRef)>, unsigned int, llvm::BitcodeModule, 
llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, 
std::allocator>> const&, llvm::DenseMap, 
llvm::detail::DenseMapPair> const&, 
llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>&)::'lambda'(std::function>> (unsigned 
int)>)::operator()(std::function>> (unsigned int)>) const 
LTO.cpp:0:0
   #9 0x56128a17d1fa std::_Function_handler, 
std::equal_to, std::allocator>, 
llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, 
std::allocator>> const&, llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>&)::'lambda'(llvm::BitcodeModule, 
llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, 
std::allocator>> const&, llvm::DenseMap, 
llvm::detail::DenseMapPair> const&, 
llvm::MapVector, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator>>>&) 
(llvm::BitcodeModule, std::reference_wrapper, 
std::reference_wrapper, std::equal_to, std::allocator>, llvm::MallocAllocator> const>, 
std::reference_wrapper> const>, 
std::reference_wrapper, std::allocator>> const>, 
std::reference_wrapper, llvm::detail::DenseMapPair> const>, 
std::reference_wrapper, 
llvm::detail::DenseMapPair>, 
std::vector, 
std::allocator)>>::_M_invoke(std::_Any_data const&) LTO.cpp:0:0
  #10 0x56128a17c851 void std::__invoke_impl)::'lambda'()&>(std::__invoke_other, 
llvm::ThreadPool::createTaskAndFuture(std::function)::'lambda'()&) 
(/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x19b2851)
  #11 0x56128a33eed1 
llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) 
(/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1b74ed1)

I am looking into it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll:1
+; RUN: opt -module-summary -o %t.bc %s
+

Testing a command does not crash does not make good use of the test. Please 
check basic properties. And add a file-level comment about the purpose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441850.
SchrodingerZhu added a comment.

- adjust comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+// IFunc function and Nameless function don't have an entry in the
+// summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  // Skip summary for indirect function aliases as summary for aliasee will not
+  // be emitted.
+  if (isa(Aliasee))
+return;
+
   bool NonRenamableLocal = 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441849.
SchrodingerZhu added a comment.

- move to proper place


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  if (isa(Aliasee))
+// Skip summary for indirect function aliases as
+// summary for aliasee will not be emitted.
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  if (isa(Aliasee))
+// Skip summary for indirect function aliases as
+// summary for aliasee will not be emitted.
+return;
+
   bool 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441848.
SchrodingerZhu added a comment.

- address cr: use IR instead


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/LTO/alias-indirect-function-lto.ll


Index: llvm/test/LTO/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  if (isa(Aliasee))
+// Skip summary for indirect function aliases as
+// summary for aliasee will not be emitted.
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/alias-indirect-function-lto.ll
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+
+@bar = alias i32 (i32), i32 (i32)* @foo
+
+@baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  if (isa(Aliasee))
+// Skip summary for indirect function aliases as
+// summary for aliasee will not be emitted.
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
  

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441846.
SchrodingerZhu added a comment.

- address cr: code brace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/LTO/alias-indirect-function-lto.c


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  if (isa(Aliasee))
+// Skip summary for indirect function aliases as
+// summary for aliasee will not be emitted.
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+
+  if (isa(Aliasee))
+// Skip summary for indirect function aliases as
+// summary for aliasee will not be emitted.
+return;
+
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
___
cfe-commits mailing 

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay requested changes to this revision.
MaskRay added inline comments.
This revision now requires changes to proceed.



Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:655
+  if (isa(Aliasee)) {
+return;
+  }

https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements



Comment at: llvm/test/LTO/alias-indirect-function-lto.c:1
+// RUN: clang -flto %s -c -o %t1
+void f() __attribute__((ifunc("g")));

llvm/test/ tests cannot use clang. You need to use tools like llvm-lto2. See 
existing tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441844.
SchrodingerZhu added a comment.

- specify target


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/LTO/alias-indirect-function-lto.c


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
___
cfe-commits mailing list

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu added a comment.

Sorry for the noise during the process. I am really new to LLVM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441830.
SchrodingerZhu added a comment.

- adjust run arg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/LTO/alias-indirect-function-lto.c


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s -c -o %t1
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s -c -o %t1
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441829.
SchrodingerZhu added a comment.

address CR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/LTO/alias-indirect-function-lto.c


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- /dev/null
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: clang -flto %s
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441828.
SchrodingerZhu edited the summary of this revision.
SchrodingerZhu added a comment.

address CR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  clang/test/Analysis/alias-indirect-function-lto.c
  llvm/test/LTO/alias-indirect-function-lto.c


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- llvm/test/LTO/alias-indirect-function-lto.c
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -flto %s
+// RUN: clang -flto %s
 void f() __attribute__((ifunc("g")));
 static void *g() { return 0; };
 void h() __attribute__((alias("f")));
-// no crash
\ No newline at end of file
+// no crash


Index: llvm/test/LTO/alias-indirect-function-lto.c
===
--- llvm/test/LTO/alias-indirect-function-lto.c
+++ llvm/test/LTO/alias-indirect-function-lto.c
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -flto %s
+// RUN: clang -flto %s
 void f() __attribute__((ifunc("g")));
 static void *g() { return 0; };
 void h() __attribute__((alias("f")));
-// no crash
\ No newline at end of file
+// no crash
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441821.
SchrodingerZhu added a comment.

undo wrong patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  clang/test/Analysis/alias-indirect-function-lto.c
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
Index: clang/test/Analysis/alias-indirect-function-lto.c
===
--- /dev/null
+++ clang/test/Analysis/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: %clang_analyze_cc1 -flto %s
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
\ No newline at end of file


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName())
-  // Nameless function don't have an entry in the summary, skip it.
+if (!Aliasee->hasName() || isa(Aliasee))
+  // IFunc function and Nameless function don't have an entry in the
+  // summary, skip it.
   continue;
 auto AliasId = VE.getValueID();
 auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,19 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
-DenseSet ) {
+static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
+DenseSet ) {
+  auto *Aliasee = A.getAliaseeObject();
+  // Skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (isa(Aliasee)) {
+return;
+  }
   bool NonRenamableLocal = isNonRenamableLocal(A);
   GlobalValueSummary::GVFlags Flags(
   A.getLinkage(), A.getVisibility(), NonRenamableLocal,
   /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
   auto AS = std::make_unique(Flags);
-  auto *Aliasee = A.getAliaseeObject();
   auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
   assert(AliaseeVI && "Alias expects aliasee summary to be available");
   assert(AliaseeVI.getSummaryList().size() == 1 &&
Index: clang/test/Analysis/alias-indirect-function-lto.c
===
--- /dev/null
+++ clang/test/Analysis/alias-indirect-function-lto.c
@@ -0,0 +1,5 @@
+// RUN: %clang_analyze_cc1 -flto %s
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
+// no crash
\ No newline at end of file
___

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441820.
SchrodingerZhu added a comment.

address CR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,7 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName() ||
-Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal)
+if (!Aliasee->hasName() || isa(Aliasee))
   // IFunc function and Nameless function don't have an entry in the
   // summary, skip it.
   continue;
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -649,23 +649,24 @@
 static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
 DenseSet ) {
   auto *Aliasee = A.getAliaseeObject();
-  // Currently, skip summary for indirect function aliases as
+  // Skip summary for indirect function aliases as
   // summary for aliasee will not be emitted.
-  if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) {
-bool NonRenamableLocal = isNonRenamableLocal(A);
-GlobalValueSummary::GVFlags Flags(
-A.getLinkage(), A.getVisibility(), NonRenamableLocal,
-/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
-auto AS = std::make_unique(Flags);
-auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
-assert(AliaseeVI && "Alias expects aliasee summary to be available");
-assert(AliaseeVI.getSummaryList().size() == 1 &&
-   "Expected a single entry per aliasee in per-module index");
-AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
-if (NonRenamableLocal)
-  CantBePromoted.insert(A.getGUID());
-Index.addGlobalValueSummary(A, std::move(AS));
+  if (isa(Aliasee)) {
+return;
   }
+  bool NonRenamableLocal = isNonRenamableLocal(A);
+  GlobalValueSummary::GVFlags Flags(
+  A.getLinkage(), A.getVisibility(), NonRenamableLocal,
+  /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
+  auto AS = std::make_unique(Flags);
+  auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
+  assert(AliaseeVI && "Alias expects aliasee summary to be available");
+  assert(AliaseeVI.getSummaryList().size() == 1 &&
+ "Expected a single entry per aliasee in per-module index");
+  AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
+  if (NonRenamableLocal)
+CantBePromoted.insert(A.getGUID());
+  Index.addGlobalValueSummary(A, std::move(AS));
 }
 
 // Set LiveRoot flag on entries matching the given value name.


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,7 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName() ||
-Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal)
+if (!Aliasee->hasName() || isa(Aliasee))
   // IFunc function and Nameless function don't have an entry in the
   // summary, skip it.
   continue;
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -649,23 +649,24 @@
 static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
 DenseSet ) {
   auto *Aliasee = A.getAliaseeObject();
-  // Currently, skip summary for indirect function aliases as
+  // Skip summary for indirect function aliases as
   // summary for aliasee will not be emitted.
-  if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) {
-bool NonRenamableLocal = isNonRenamableLocal(A);
-GlobalValueSummary::GVFlags Flags(
-A.getLinkage(), A.getVisibility(), NonRenamableLocal,
-/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
-auto AS = std::make_unique(Flags);
-auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
-assert(AliaseeVI && "Alias expects aliasee summary to be available");
-assert(AliaseeVI.getSummaryList().size() == 1 &&
-   "Expected a single entry per aliasee in per-module index");
-AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
-if (NonRenamableLocal)
-  CantBePromoted.insert(A.getGUID());
-

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 441819.
SchrodingerZhu added a comment.

address CR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,7 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName() ||
-Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal)
+if (!Aliasee->hasName() || isa(Aliasee))
   // IFunc function and Nameless function don't have an entry in the
   // summary, skip it.
   continue;
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -649,23 +649,24 @@
 static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias 
,
 DenseSet ) {
   auto *Aliasee = A.getAliaseeObject();
-  // Currently, skip summary for indirect function aliases as
+  // Skip summary for indirect function aliases as
   // summary for aliasee will not be emitted.
-  if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) {
-bool NonRenamableLocal = isNonRenamableLocal(A);
-GlobalValueSummary::GVFlags Flags(
-A.getLinkage(), A.getVisibility(), NonRenamableLocal,
-/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
-auto AS = std::make_unique(Flags);
-auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
-assert(AliaseeVI && "Alias expects aliasee summary to be available");
-assert(AliaseeVI.getSummaryList().size() == 1 &&
-   "Expected a single entry per aliasee in per-module index");
-AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
-if (NonRenamableLocal)
-  CantBePromoted.insert(A.getGUID());
-Index.addGlobalValueSummary(A, std::move(AS));
+  if (isa(Aliasee)) {
+return;
   }
+  bool NonRenamableLocal = isNonRenamableLocal(A);
+  GlobalValueSummary::GVFlags Flags(
+  A.getLinkage(), A.getVisibility(), NonRenamableLocal,
+  /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
+  auto AS = std::make_unique(Flags);
+  auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
+  assert(AliaseeVI && "Alias expects aliasee summary to be available");
+  assert(AliaseeVI.getSummaryList().size() == 1 &&
+ "Expected a single entry per aliasee in per-module index");
+  AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
+  if (NonRenamableLocal)
+CantBePromoted.insert(A.getGUID());
+  Index.addGlobalValueSummary(A, std::move(AS));
 }
 
 // Set LiveRoot flag on entries matching the given value name.


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,7 @@
 
   for (const GlobalAlias  : M.aliases()) {
 auto *Aliasee = A.getAliaseeObject();
-if (!Aliasee->hasName() ||
-Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal)
+if (!Aliasee->hasName() || isa(Aliasee))
   // IFunc function and Nameless function don't have an entry in the
   // summary, skip it.
   continue;
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -649,23 +649,24 @@
 static void computeAliasSummary(ModuleSummaryIndex , const GlobalAlias ,
 DenseSet ) {
   auto *Aliasee = A.getAliaseeObject();
-  // Currently, skip summary for indirect function aliases as
+  // Skip summary for indirect function aliases as
   // summary for aliasee will not be emitted.
-  if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) {
-bool NonRenamableLocal = isNonRenamableLocal(A);
-GlobalValueSummary::GVFlags Flags(
-A.getLinkage(), A.getVisibility(), NonRenamableLocal,
-/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
-auto AS = std::make_unique(Flags);
-auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
-assert(AliaseeVI && "Alias expects aliasee summary to be available");
-assert(AliaseeVI.getSummaryList().size() == 1 &&
-   "Expected a single entry per aliasee in per-module index");
-AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
-if (NonRenamableLocal)
-  CantBePromoted.insert(A.getGUID());
-

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:654
+  // summary for aliasee will not be emitted.
+  if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) {
+bool NonRenamableLocal = isNonRenamableLocal(A);

MaskRay wrote:
> Use an early return to avoid indenting so many lines.
Also, please use `isa(Aliasee)` instead of inspecting the value ID.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> As https://github.com/llvm/llvm-project/issues/56290 indicates

Write the description, followed by `Fix(es)? 
https://github.com/llvm/llvm-project/issues/56290` on a separate line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits