-
Notifications
You must be signed in to change notification settings - Fork 738
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
[SYCL][ESIMD] Rework -O0 behavior #12612
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//=-- ESIMDRemoveOptnoneNoinline.cpp - remove optnone/noinline for ESIMD --=// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//=------------------------------------------------------------------------=// | ||
// The GPU backend for ESIMD does not support debugging and we often see crashes | ||
// or wrong answers if we do not optimize. Remove optnone and noinline from | ||
// ESIMD functions so users at least can run their programs and get the | ||
// right answer. | ||
//=------------------------------------------------------------------------=// | ||
|
||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/SYCLLowerIR/ESIMD/ESIMDUtils.h" | ||
#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::esimd; | ||
|
||
cl::opt<bool> AllowOptnoneNoinline( | ||
"esimd-allow-optnone-noinline", llvm::cl::Optional, llvm::cl::Hidden, | ||
llvm::cl::desc("Allow optnone and noinline."), llvm::cl::init(false)); | ||
|
||
PreservedAnalyses ESIMDRemoveOptnoneNoinlinePass::run(Module &M, | ||
ModuleAnalysisManager &) { | ||
if (AllowOptnoneNoinline) | ||
return PreservedAnalyses::all(); | ||
|
||
// TODO: Remove this pass once VC supports debugging. | ||
bool Modified = false; | ||
for (auto &F : M.functions()) { | ||
if (!isESIMD(F) || F.hasFnAttribute("CMGenxSIMT")) | ||
continue; | ||
F.removeFnAttr(Attribute::OptimizeNone); | ||
F.removeFnAttr(Attribute::NoInline); | ||
Modified = true; | ||
} | ||
return Modified ? PreservedAnalyses::none() : PreservedAnalyses::all(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1834,6 +1834,15 @@ bool SYCLLowerESIMDPass::prepareForAlwaysInliner(Module &M) { | |
continue; | ||
} | ||
|
||
// If we are splitting by ESIMD, we are guarenteed the entire | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this code still needed after adding the special pass that remove those 2 attributes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I tested many combinations of with/without different changes in this PR and everything we currently have is required. |
||
// module only contains ESIMD code, so remove optnone/noinline | ||
// from ALL functions as VC does not support these attributes | ||
// and programs produce wrong answers or crash if they are kept. | ||
if (!ModuleContainsScalarCode && !F.hasFnAttribute("CMGenxSIMT")) { | ||
F.removeFnAttr(Attribute::NoInline); | ||
F.removeFnAttr(Attribute::OptimizeNone); | ||
} | ||
|
||
// TODO: The next code and comment was placed to ESIMDLoweringPass | ||
// 2 years ago, when GPU VC BE did not support function calls and | ||
// required everything to be inlined right into the kernel unless | ||
|
@@ -1939,17 +1948,6 @@ size_t SYCLLowerESIMDPass::runOnFunction(Function &F, | |
SmallVector<CallInst *, 32> ESIMDIntrCalls; | ||
SmallVector<Instruction *, 8> ToErase; | ||
|
||
// The VC backend doesn't support debugging, and trying to use | ||
// non-optimized code often produces crashes or wrong answers. | ||
// The recommendation from the VC team was always optimize code, | ||
// even if the user requested no optimization. We already drop | ||
// debugging flags in the SYCL runtime, so also drop optnone and | ||
// noinline here. | ||
if (isESIMD(F) && F.hasFnAttribute(Attribute::OptimizeNone)) { | ||
F.removeFnAttr(Attribute::OptimizeNone); | ||
F.removeFnAttr(Attribute::NoInline); | ||
} | ||
|
||
for (Instruction &I : instructions(F)) { | ||
if (auto CastOp = dyn_cast<llvm::CastInst>(&I)) { | ||
llvm::Type *DstTy = CastOp->getDestTy(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
; This ensures we remove optnone from ESIMD functions unless they are SIMT or we didn't split ESIMD code out. | ||
; RUN: sycl-post-link -split-esimd -lower-esimd -S < %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK,CHECK-ESIMD-SPLIT | ||
|
||
; RUN: sycl-post-link -lower-esimd -S < %s -o %t1.table | ||
; RUN: FileCheck %s -input-file=%t1_esimd_0.ll --check-prefixes CHECK,CHECK-NO-ESIMD-SPLIT | ||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
define dso_local spir_func void @esimd() #0 !sycl_explicit_simd !0 { | ||
; CHECK: void @esimd() #[[#ESIMDAttr:]] | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @esimd_simt() #1 !sycl_explicit_simd !0 { | ||
; CHECK: void @esimd_simt() #[[#ESIMDSIMTAttr:]] | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @sycl() #0 { | ||
; CHECK: spir_func void @sycl() #[[#ESIMDAttr]] | ||
ret void | ||
} | ||
; CHECK-ESIMD-SPLIT: attributes #[[#ESIMDAttr]] = | ||
; CHECK-ESIMD-SPLIT-NOT: optnone | ||
; CHECK-NO-ESIMD-SPLIT: attributes #[[#ESIMDAttr]] = {{{.*}}optnone{{.*}}} | ||
; CHECK: attributes #[[#ESIMDSIMTAttr]] = {{{.*}}optnone | ||
; CHECK-SAME: "CMGenxSIMT" | ||
; CHECK-SAME: } | ||
attributes #0 = { noinline optnone convergent } | ||
attributes #1 = { noinline optnone convergent "CMGenxSIMT"} | ||
!0 = !{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import platform | ||
|
||
config.substitutions.append(("%clang_O0", "-O0 -mllvm -esimd-allow-optnone-noinline")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am okay with this ESIMD change.