Skip to content

Commit

Permalink
make code assumption in get_global_id optional
Browse files Browse the repository at this point in the history
Stateless to stateful optimization checks if the offset of GEP
instruction is positive. This is done with the assumption that the sign
bit of global_id will be always off. This assume interferes with
instcombine pass, so it is skipped unless really needed, that is:
  1) StatelessToStateful pass is enabled, AND
  2) Buffers don't use implicit bufferOffsetArg.
  • Loading branch information
pkwasnie-intel authored and igcbot committed Feb 24, 2025
1 parent 6c471b3 commit 26a57ba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions IGC/BiFModule/Headers/bif_flag_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ BIF_FLAG_CONTROL(bool, ForceL1Prefetch)
BIF_FLAG_CONTROL(bool, UseHighAccuracyMath)
BIF_FLAG_CONTROL(bool, EnableSWSrgbWrites)
BIF_FLAG_CONTROL(int, MaxHWThreadIDPerSubDevice)
BIF_FLAG_CONTROL(bool, UseAssumeInGetGlobalId)
BIF_FLAG_CONTROL(int, JointMatrixLoadStoreOpt)
BIF_FLAG_CONTROL(bool, UseOOBChecks)
#endif // __BIF_FLAG_CONTROL_H__
3 changes: 2 additions & 1 deletion IGC/BiFModule/Implementation/workitem.cl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ size_t OVERLOADABLE __intel_GlobalInvocationId(uint dim)
// We want to show, that the value is positive.
// On LLVM level, where the signedness of the type is lost, the only way to prove
// that the value is positive is to check the sign bit.
__builtin_assume((v & 0x8000000000000000ULL) == 0);
if (BIF_FLAG_CTRL_GET(UseAssumeInGetGlobalId))
__builtin_assume((v & 0x8000000000000000ULL) == 0);
#endif

return v;
Expand Down
12 changes: 12 additions & 0 deletions IGC/Compiler/Builtins/BIFFlagCtrl/BIFFlagCtrlResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ void BIFFlagCtrlResolution::FillFlagCtrl() {
BIF_FLAG_CTRL_SET(UseHighAccuracyMath, false);
}

// Stateless to stateful optimization checks if the offset of GEP instruction is positive.
// This is done with the assumption that the sign bit of global_id will be always off.
// This assume interferes with instcombine pass, so it is skipped unless really needed, that is:
// 1) StatelessToStateful pass is enabled, AND
// 2) Buffers don't use implicit bufferOffsetArg.
bool useAssumeInGetGlobalId = PtrCGC->m_DriverInfo.SupportsStatelessToStatefulBufferTransformation() &&
!PtrCGC->getModuleMetaData()->compOpt.GreaterThan4GBBufferRequired &&
IGC_IS_FLAG_ENABLED(EnableStatelessToStateful) &&
!((IGC_IS_FLAG_ENABLED(EnableSupportBufferOffset) || PtrCGC->getModuleMetaData()->compOpt.HasBufferOffsetArg)) &&
!PtrCGC->getModuleMetaData()->compOpt.OptDisable;
BIF_FLAG_CTRL_SET(UseAssumeInGetGlobalId, useAssumeInGetGlobalId);

BIF_FLAG_CTRL_SET(EnableSWSrgbWrites,
IGC_GET_FLAG_VALUE(cl_khr_srgb_image_writes));
BIF_FLAG_CTRL_SET(MaxHWThreadIDPerSubDevice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SPDX-License-Identifier: MIT
BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME),

#define BIF_FLAG_CTRL_SET(BIF_FLAG_NAME, BIF_FLAG_VALUE) \
ListDelegates.emplace(BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME), [this]() -> bool { \
ListDelegates.emplace(BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME), [&]() -> bool { \
return replace(BIF_FLAG_VALUE, \
pModule->getGlobalVariable(BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME))); \
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void GenXBIFFlagCtrlResolution::FillFlagCtrl() {
BIF_FLAG_CTRL_SET(ProfilingTimerResolution, 0.0f);
BIF_FLAG_CTRL_SET(UseMathWithLUT, false);
BIF_FLAG_CTRL_SET(UseHighAccuracyMath, false);
BIF_FLAG_CTRL_SET(UseAssumeInGetGlobalId, true);
// FIXME: target specific, but subtarget cannot be reached in middle-end.
BIF_FLAG_CTRL_SET(HasInt64SLMAtomicCAS, false);
BIF_FLAG_CTRL_SET(JointMatrixLoadStoreOpt, 3);
Expand Down

0 comments on commit 26a57ba

Please sign in to comment.