Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions clang/test/CodeGenSYCL/simplifycfg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -flegacy-pass-manager -mllvm -sycl-opt %s -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -fno-legacy-pass-manager -mllvm -sycl-opt %s -emit-llvm -o - | FileCheck %s
//
// This test checks that foo (which is @_Z3foov) is called twice after O3 optimizations.
//
// Usually clang with SimplifyCFG pass optimizes constructs like:
// if (i % 2 == 0)
// func();
// else
// func();
//
// into one simple func() invocation.
// This behaviour might be wrong in cases when func's behaviour depends on
// a place where it is written.
// There is a relevant discussion about introducing
// a reliable tool for such cases: https://reviews.llvm.org/D85603

// CHECK: tail call spir_func void @_Z3foov()
// CHECK: tail call spir_func void @_Z3foov()

SYCL_EXTERNAL void foo();

SYCL_EXTERNAL void bar(int i) {
if (i % 2 == 0) {
foo();
} else {
foo();
}
}
8 changes: 6 additions & 2 deletions llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,12 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
for (auto &C : ScalarOptimizerLateEPCallbacks)
C(FPM, Level);

FPM.addPass(SimplifyCFGPass(
SimplifyCFGOptions().hoistCommonInsts(true).sinkCommonInsts(true)));
if (SYCLOptimizationMode)
FPM.addPass(SimplifyCFGPass());
else
FPM.addPass(SimplifyCFGPass(
SimplifyCFGOptions().hoistCommonInsts(true).sinkCommonInsts(true)));

FPM.addPass(InstCombinePass());
invokePeepholeEPCallbacks(FPM, Level);

Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,12 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
MPM.add(createLoopRerollPass());

// Merge & remove BBs and sink & hoist common instructions.
MPM.add(createCFGSimplificationPass(
SimplifyCFGOptions().hoistCommonInsts(true).sinkCommonInsts(true)));
if (SYCLOptimizationMode)
MPM.add(createCFGSimplificationPass());
else
MPM.add(createCFGSimplificationPass(
SimplifyCFGOptions().hoistCommonInsts(true).sinkCommonInsts(true)));

// Clean up after everything.
MPM.add(createInstructionCombiningPass());
addExtensionsToPM(EP_Peephole, MPM);
Expand Down