Skip to content

Commit

Permalink
Introduce an intrinsic for optimization fence in VC
Browse files Browse the repository at this point in the history
The intrinsic prevents instructions from being combined or reassociated.
  • Loading branch information
vmustya authored and igcbot committed Oct 22, 2024
1 parent 13f3921 commit bc730c5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@
"memory_effects":
{ "access": "NoModRef" }, },

## ``llvm.vc.internal.optimization.fence`` : optimization fence
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
##
## * arg0: input value
##
## * Return value: the same as arg0
##
## The purpose of the intrinsic is to prevent the compiler from
## optimizing the value.
##
"optimization_fence" : { "result": "any",
"arguments": [0],
"attributes": "NoMem", },

### --------------
### ALU intrinsics
### --------------
Expand Down
4 changes: 4 additions & 0 deletions IGC/VectorCompiler/lib/GenXCodeGen/GenXLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,10 @@ bool GenXLowering::processInst(Instruction *Inst) {
return lowerHardwareThreadID(CI);
case vc::InternalIntrinsic::logical_thread_id:
return lowerLogicalThreadID(CI);
case vc::InternalIntrinsic::optimization_fence:
CI->replaceAllUsesWith(CI->getOperand(0));
ToErase.push_back(CI);
return true;
case GenXIntrinsic::genx_nbarrier_arrive:
return lowerNamedBarrierArrive(CI);
case GenXIntrinsic::genx_dpas:
Expand Down
18 changes: 18 additions & 0 deletions IGC/VectorCompiler/test/Lowering/optimization-fence.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2024 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================

; RUN: %opt %use_old_pass_manager% -GenXLowering -march=genx64 -mcpu=XeHPC -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s

declare <16 x i32> @llvm.vc.internal.optimization.fence.v16i32(<16 x i32>)

; CHECK-LABEL: @test(
define <16 x i32> @test(<16 x i32> %a) {
; CHECK: ret <16 x i32> %a
%call = call <16 x i32> @llvm.vc.internal.optimization.fence.v16i32(<16 x i32> %a)
ret <16 x i32> %call
}

0 comments on commit bc730c5

Please sign in to comment.