Skip to content

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.

@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;
+}

@MaggieYingYi
Copy link
Contributor Author

gentle pinging ...

Copy link
Collaborator

@wjristow wjristow left a comment

Choose a reason for hiding this comment

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

LGTM

/// Pass pipeline for full is different.
// RUN: not diff %t.0.txt %t.3.txt
/// Pass pipeline for full is different. Unified uses the full Linux pipeline except ThinLTOBitcodeWriterPass vs BitcodeWriterPass.
// RUN: not diff -u %t.0.txt %t.3.txt | FileCheck %s --check-prefix=DIFF --implicit-check-not="{{^[-+!<>] }}"
Copy link
Member

Choose a reason for hiding this comment

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

I hope that diff -u is portable. If it is not (e.g. unsupported on niche platforms), they might add some UNSUPPORTED: , but it's not a thing the author and reviewers should be concerned with :)

@MaggieYingYi MaggieYingYi force-pushed the yingyi/main/unified_LTO_tests branch 4 times, most recently from 647766a to 673cdd3 Compare August 27, 2025 08:32
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/nonunified LTO checks are enhanced in this PR:
1. Check that the default, unified, and non-unified behavior for asan-unified-lto.ll all match (irrespective of what the default unified/nonunified behavior is).
2. Check that the difference in behavior for 'unified' and 'full' runs is (regarding the passes) is what is expected (rather than simply that they are different).
@MaggieYingYi MaggieYingYi force-pushed the yingyi/main/unified_LTO_tests branch from 673cdd3 to ab2917f Compare August 28, 2025 15:19
@MaggieYingYi MaggieYingYi merged commit 111844a into llvm:main Aug 28, 2025
9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 28, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building clang at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/12396

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libarcher :: races/parallel-simple.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang -fopenmp  -gdwarf-4 -O1 -fsanitize=thread  -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src   /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/parallel-simple.c -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/parallel-simple.c.tmp -latomic && env TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1' /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/parallel-simple.c.tmp 2>&1 | tee /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/parallel-simple.c.tmp.log | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/parallel-simple.c
# executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang -fopenmp -gdwarf-4 -O1 -fsanitize=thread -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/parallel-simple.c -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/parallel-simple.c.tmp -latomic
# note: command had no output on stdout or stderr
# executed command: env TSAN_OPTIONS=ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/parallel-simple.c.tmp
# note: command had no output on stdout or stderr
# executed command: tee /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/parallel-simple.c.tmp.log
# note: command had no output on stdout or stderr
# executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/parallel-simple.c
# .---command stderr------------
# | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/parallel-simple.c:36:11: error: CHECK: expected string not found in input
# | // CHECK: ThreadSanitizer: reported {{[1-7]}} warnings
# |           ^
# | <stdin>:23:5: note: scanning from here
# | DONE
# |     ^
# | <stdin>:24:1: note: possible intended match here
# | ThreadSanitizer: thread T4 finished with ignores enabled, created at:
# | ^
# | 
# | Input file: <stdin>
# | Check file: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/parallel-simple.c
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |            18:  #0 pthread_create /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1075:3 (parallel-simple.c.tmp+0xa3caa) 
# |            19:  #1 __kmp_create_worker z_Linux_util.cpp (libomp.so+0xcb8a2) 
# |            20:  
# |            21: SUMMARY: ThreadSanitizer: data race /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/parallel-simple.c:23:8 in main.omp_outlined_debug__ 
# |            22: ================== 
# |            23: DONE 
# | check:36'0         X error: no match found
# |            24: ThreadSanitizer: thread T4 finished with ignores enabled, created at: 
# | check:36'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | check:36'1     ?                                                                      possible intended match
# |            25:  #0 pthread_create /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1075:3 (parallel-simple.c.tmp+0xa3caa) 
# | check:36'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            26:  #1 __kmp_create_worker z_Linux_util.cpp (libomp.so+0xcb8a2) 
# | check:36'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            27:  
...

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.

5 participants