Skip to content

Commit 26a57ba

Browse files
pkwasnie-inteligcbot
authored andcommitted
make code assumption in get_global_id optional
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.
1 parent 6c471b3 commit 26a57ba

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

IGC/BiFModule/Headers/bif_flag_controls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ BIF_FLAG_CONTROL(bool, ForceL1Prefetch)
3535
BIF_FLAG_CONTROL(bool, UseHighAccuracyMath)
3636
BIF_FLAG_CONTROL(bool, EnableSWSrgbWrites)
3737
BIF_FLAG_CONTROL(int, MaxHWThreadIDPerSubDevice)
38+
BIF_FLAG_CONTROL(bool, UseAssumeInGetGlobalId)
3839
BIF_FLAG_CONTROL(int, JointMatrixLoadStoreOpt)
3940
BIF_FLAG_CONTROL(bool, UseOOBChecks)
4041
#endif // __BIF_FLAG_CONTROL_H__

IGC/BiFModule/Implementation/workitem.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ size_t OVERLOADABLE __intel_GlobalInvocationId(uint dim)
113113
// We want to show, that the value is positive.
114114
// On LLVM level, where the signedness of the type is lost, the only way to prove
115115
// that the value is positive is to check the sign bit.
116-
__builtin_assume((v & 0x8000000000000000ULL) == 0);
116+
if (BIF_FLAG_CTRL_GET(UseAssumeInGetGlobalId))
117+
__builtin_assume((v & 0x8000000000000000ULL) == 0);
117118
#endif
118119

119120
return v;

IGC/Compiler/Builtins/BIFFlagCtrl/BIFFlagCtrlResolution.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ void BIFFlagCtrlResolution::FillFlagCtrl() {
9292
BIF_FLAG_CTRL_SET(UseHighAccuracyMath, false);
9393
}
9494

95+
// Stateless to stateful optimization checks if the offset of GEP instruction is positive.
96+
// This is done with the assumption that the sign bit of global_id will be always off.
97+
// This assume interferes with instcombine pass, so it is skipped unless really needed, that is:
98+
// 1) StatelessToStateful pass is enabled, AND
99+
// 2) Buffers don't use implicit bufferOffsetArg.
100+
bool useAssumeInGetGlobalId = PtrCGC->m_DriverInfo.SupportsStatelessToStatefulBufferTransformation() &&
101+
!PtrCGC->getModuleMetaData()->compOpt.GreaterThan4GBBufferRequired &&
102+
IGC_IS_FLAG_ENABLED(EnableStatelessToStateful) &&
103+
!((IGC_IS_FLAG_ENABLED(EnableSupportBufferOffset) || PtrCGC->getModuleMetaData()->compOpt.HasBufferOffsetArg)) &&
104+
!PtrCGC->getModuleMetaData()->compOpt.OptDisable;
105+
BIF_FLAG_CTRL_SET(UseAssumeInGetGlobalId, useAssumeInGetGlobalId);
106+
95107
BIF_FLAG_CTRL_SET(EnableSWSrgbWrites,
96108
IGC_GET_FLAG_VALUE(cl_khr_srgb_image_writes));
97109
BIF_FLAG_CTRL_SET(MaxHWThreadIDPerSubDevice,

IGC/Compiler/Builtins/BIFFlagCtrl/BIFFlagCtrlResolution.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SPDX-License-Identifier: MIT
2222
BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME),
2323

2424
#define BIF_FLAG_CTRL_SET(BIF_FLAG_NAME, BIF_FLAG_VALUE) \
25-
ListDelegates.emplace(BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME), [this]() -> bool { \
25+
ListDelegates.emplace(BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME), [&]() -> bool { \
2626
return replace(BIF_FLAG_VALUE, \
2727
pModule->getGlobalVariable(BIF_FLAG_CTRL_N_S(BIF_FLAG_NAME))); \
2828
})

IGC/VectorCompiler/lib/GenXOpts/CMTrans/GenXBIFFlagCtrlResolution.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void GenXBIFFlagCtrlResolution::FillFlagCtrl() {
7777
BIF_FLAG_CTRL_SET(ProfilingTimerResolution, 0.0f);
7878
BIF_FLAG_CTRL_SET(UseMathWithLUT, false);
7979
BIF_FLAG_CTRL_SET(UseHighAccuracyMath, false);
80+
BIF_FLAG_CTRL_SET(UseAssumeInGetGlobalId, true);
8081
// FIXME: target specific, but subtarget cannot be reached in middle-end.
8182
BIF_FLAG_CTRL_SET(HasInt64SLMAtomicCAS, false);
8283
BIF_FLAG_CTRL_SET(JointMatrixLoadStoreOpt, 3);

0 commit comments

Comments
 (0)