Skip to content

Commit d4f76aa

Browse files
mshelegoigcbot
authored andcommitted
Support O0 for new pass manager on LLVM16
Prevent crashes when -no-optimize option is used with new PM
1 parent 539f561 commit d4f76aa

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

IGC/VectorCompiler/lib/Driver/Driver.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,13 @@ createTargetMachine(const vc::CompileOptions &Opts,
365365
static void optimizeIR(const vc::CompileOptions &Opts,
366366
const vc::ExternalData &ExtData, TargetMachine &TM,
367367
Module &M) {
368-
368+
#if LLVM_VERSION_MAJOR < 16
369369
unsigned OptLevel;
370370
if (Opts.IROptLevel == vc::OptimizerLevel::None)
371371
OptLevel = 0;
372372
else
373373
OptLevel = 2;
374374

375-
#if LLVM_VERSION_MAJOR < 16
376375
vc::PassManager PerModulePasses;
377376
auto *BC = new GenXBackendConfig{
378377
createBackendOptions(Opts),
@@ -450,9 +449,23 @@ static void optimizeIR(const vc::CompileOptions &Opts,
450449
PB.registerLoopAnalyses(LAM);
451450
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
452451

453-
llvm::ModulePassManager MPM = PB.buildPerModuleDefaultPipeline(
454-
OptLevel == 2 ? llvm::OptimizationLevel::O2
455-
: llvm::OptimizationLevel::O0);
452+
llvm::OptimizationLevel OptLevel;
453+
if (Opts.IROptLevel == vc::OptimizerLevel::None)
454+
OptLevel = llvm::OptimizationLevel::O0;
455+
else
456+
OptLevel = llvm::OptimizationLevel::O2;
457+
458+
#if LLVM_VERSION_MAJOR < 17
459+
// On llvm-16 a separate method must be used to build default O0 pipeline,
460+
// otherwise it hits an assertion.
461+
llvm::ModulePassManager MPM;
462+
if (OptLevel == llvm::OptimizationLevel::O0)
463+
MPM = PB.buildO0DefaultPipeline(OptLevel);
464+
else
465+
MPM = PB.buildPerModuleDefaultPipeline(OptLevel);
466+
#else // LLVM_VERSION_MAJOR < 17
467+
llvm::ModulePassManager MPM = PB.buildPerModuleDefaultPipeline(OptLevel);
468+
#endif // LLVM_VERSION_MAJOR < 17
456469

457470
MPM.run(M, MAM);
458471
#endif // LLVM_VERSION_MAJOR < 16

IGC/ocloc_tests/VC/new_pw_O0.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; REQUIRES: regkeys, pvc-supported, llvm-16-plus
10+
11+
; LLVM with opaque pointers:
12+
; RUN: llvm-as -opaque-pointers=1 %s -o %t.bc
13+
; RUN: ocloc -device pvc -llvm_input -options "-vc-codegen -no-optimize -igc_opts 'EnableOpaquePointersBackend=1, PrintToConsole=1'" -file %t.bc
14+
15+
; LLVM with typed pointers:
16+
; RUN: llvm-as -opaque-pointers=0 %s -o %t.bc
17+
; RUN: ocloc -device pvc -llvm_input -options "-vc-codegen -no-optimize -igc_opts 'PrintToConsole=1'" -file %t.bc
18+
19+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
20+
target triple = "spir64-unknown-unknown"
21+
22+
define spir_kernel void @test(i32 addrspace(1)* %in, i32 addrspace(1)* %out, i32 %arg) {
23+
entry:
24+
%val = load i32, i32 addrspace(1)* %in
25+
%add = add i32 %val, %arg
26+
store i32 %add, i32 addrspace(1)* %out
27+
ret void
28+
}

0 commit comments

Comments
 (0)