Skip to content

[LTO] Add unified LTO tests for the PS targets. #148229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MaggieYingYi
Copy link
Contributor

For the PS targets, unified LTO pipeline is used as default behaviour when enabling LTO. Other targets use Distinct LTO pipeline behaviour as default behaviours. Unified LTO tests are added in this PR:

  1. clang/test/CodeGen/asan-unified-lto.ll: add a RUN line to check the explicit Distinct LTO pipeline behavior for PS targets.
  2. clang/test/CodeGen/unified-lto-pipeline-ps.c: a new test for PS targets.

For the PS targets, unified LTO pipeline is used as default behaviour when enabling LTO. Other targets use Distinct LTO pipeline behaviour as default behavious. Unified LTO tests are added in this PR:
1. clang/test/CodeGen/asan-unified-lto.ll: add a RUN line to check the explicit Distinct LTO pipeline behavior for PS targets.
2. clang/test/CodeGen/unified-lto-pipeline-ps.c: a new test for PS targets.
@MaggieYingYi MaggieYingYi self-assigned this Jul 11, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2025

@llvm/pr-subscribers-clang

Author: Ying Yi (MaggieYingYi)

Changes

For the PS targets, unified LTO pipeline is used as default behaviour when enabling LTO. Other targets use Distinct LTO pipeline behaviour as default behaviours. Unified LTO tests are added in this PR:

  1. clang/test/CodeGen/asan-unified-lto.ll: add a RUN line to check the explicit Distinct LTO pipeline behavior for PS targets.
  2. clang/test/CodeGen/unified-lto-pipeline-ps.c: a new test for PS targets.

Full diff: https://github.com/llvm/llvm-project/pull/148229.diff

2 Files Affected:

  • (modified) clang/test/CodeGen/asan-unified-lto.ll (+1)
  • (added) clang/test/CodeGen/unified-lto-pipeline-ps.c (+33)
diff --git a/clang/test/CodeGen/asan-unified-lto.ll b/clang/test/CodeGen/asan-unified-lto.ll
index 7b790d49e3fdb..21734e1fd8f67 100644
--- a/clang/test/CodeGen/asan-unified-lto.ll
+++ b/clang/test/CodeGen/asan-unified-lto.ll
@@ -5,6 +5,7 @@
 
 ; RUN: %clang_cc1 -emit-llvm-bc -O1 -flto -fsanitize=address -o - -x ir < %s | llvm-dis -o - | FileCheck %s
 ; RUN: %clang_cc1 -emit-llvm-bc -O1 -flto -funified-lto -fsanitize=address -o - -x ir < %s | llvm-dis -o - | FileCheck %s
+; RUN: %clang_cc1 -emit-llvm-bc -O1 -flto -fno-unified-lto -fsanitize=address -o - -x ir < %s | llvm-dis -o - | FileCheck %s
 ; CHECK: @anon.3ee0898e5200a57350fed5485ae5d237
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/clang/test/CodeGen/unified-lto-pipeline-ps.c b/clang/test/CodeGen/unified-lto-pipeline-ps.c
new file mode 100644
index 0000000000000..5849bf051dfec
--- /dev/null
+++ b/clang/test/CodeGen/unified-lto-pipeline-ps.c
@@ -0,0 +1,33 @@
+// RUN: %clang -flto=thin --target=x86_64-scei-ps4 -O2 -c %s -o %t.ps4.tu -Xclang -fdebug-pass-manager 2>%t.ps4.tu.txt
+// RUN: %clang -flto=thin --target=x86_64-sie-ps5  -O2 -c %s -o %t.ps5.tu -Xclang -fdebug-pass-manager 2>%t.ps5.tu.txt
+// RUN: %clang -flto=full --target=x86_64-scei-ps4 -O2 -c %s -o %t.ps4.fu -Xclang -fdebug-pass-manager 2>%t.ps4.fu.txt
+// RUN: %clang -flto=full --target=x86_64-sie-ps5  -O2 -c %s -o %t.ps5.fu -Xclang -fdebug-pass-manager 2>%t.ps5.fu.txt
+// RUN: %clang -flto=thin -fno-unified-lto --target=x86_64-scei-ps4 -O2 -c %s -o %t.ps4.tn -Xclang -fdebug-pass-manager 2>%t.ps4.tn.txt
+// RUN: %clang -flto=full -fno-unified-lto --target=x86_64-scei-ps4 -O2 -c %s -o %t.ps4.fn -Xclang -fdebug-pass-manager 2>%t.ps4.fn.txt
+// RUN: %clang -flto=thin --target=x86_64-unknown-linux -O2 -c %s -o %t.l.tn -Xclang -fdebug-pass-manager 2>%t.l.tn.txt
+// RUN: %clang -flto=full --target=x86_64-unknown-linux -O2 -c %s -o %t.l.fn -Xclang -fdebug-pass-manager 2>%t.l.fn.txt
+/// Pre-link bitcode and pass pipelines should be identical for (unified) thin/full on PS4/PS5.
+/// Pipeline on PS5 is also identical (but bitcode won't be identical to PS4 due to the embedded triple).
+// RUN: cmp %t.ps4.tu %t.ps4.fu
+// RUN: cmp %t.ps5.tu %t.ps5.fu
+// RUN: diff %t.ps4.tu.txt %t.ps4.fu.txt
+// RUN: diff %t.ps4.tu.txt %t.ps5.tu.txt
+// RUN: diff %t.ps5.tu.txt %t.ps5.fu.txt
+// RUN: FileCheck --input-file %t.ps4.tu.txt %s
+// CHECK: ThinLTOBitcodeWriterPass
+/// Non-unified PS4/PS5 pass pipelines match Linux. Thin/full are different.
+// RUN: not diff %t.ps4.tn.txt %t.ps4.fn.txt
+// RUN: diff %t.ps4.tn.txt %t.l.tn.txt
+// RUN: diff %t.ps4.fn.txt %t.l.fn.txt
+/// PS4/PS5 unified use the full Linux pipeline (except ThinLTOBitcodeWriterPass vs BitcodeWriterPass).
+// RUN: not diff -u %t.ps4.tu.txt %t.l.fn.txt | FileCheck %s --check-prefix=DIFF --implicit-check-not="{{^[-+!<>] }}"
+// DIFF:      -Running pass: ThinLTOBitcodeWriterPass
+// DIFF-NEXT: +Running pass: BitcodeWriterPass
+
+int foo() {
+  return 2 + 2;
+}
+
+int bar() {
+  return foo() + 1;
+}

@@ -0,0 +1,33 @@
// RUN: %clang -flto=thin --target=x86_64-scei-ps4 -O2 -c %s -o %t.ps4.tu -Xclang -fdebug-pass-manager 2>%t.ps4.tu.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unified-lto-pipeline.c is present and serves the purpose. For target-generic codegen features, we usually test just one platform (it doesn't really scale if every platform that does no customization wants to add their own tests). If PS ever customizes the behavior, we can accept the new test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MaskRay. Yes, unified-lto-pipeline.c serves the purpose. The initial test checked that pass pipeline for full is different from unified-lto. I added a new FileCheck for testing the different pass pipeline between full-lto and unified-lto. In addition, I had removed the clang/test/CodeGen/unified-lto-pipeline-ps.c. Please see commit 5b63ac5 for the details.

…ecking the different pipeline between full-lto and unified-lto.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants