Skip to content

Commit ffcd29a

Browse files
mshelegoigcbot
authored andcommitted
Add a pass to remove freeze instructions
Completely remove all freeze instructions before running any codegen passes
1 parent 8f8fc16 commit ffcd29a

File tree

8 files changed

+104
-55
lines changed

8 files changed

+104
-55
lines changed

IGC/VectorCompiler/include/GenX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ ModulePass *createGenXDetectPointerArgPass();
162162
FunctionPass *createGenXLCECalculationPass();
163163
FunctionPass *createGenXFloatControlPass();
164164
ModulePass *createGenXCountIndirectStatelessPass();
165+
FunctionPass *createGenXUnfreezePass();
165166

166167
namespace genx {
167168

IGC/VectorCompiler/lib/GenXCodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ set(CODEGEN_SOURCES
9696
GenXTargetMachine.cpp
9797
GenXTidyControlFlow.cpp
9898
GenXUnbaling.cpp
99+
GenXUnfreeze.cpp
99100
GenXUtil.cpp
100101
GenXVectorCombiner.cpp
101102
GenXVectorDecomposer.cpp

IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ class GenXPatternMatch : public FunctionPass,
168168

169169
void visitUDiv(BinaryOperator &I);
170170

171-
void visitFreezeInst(FreezeInst &I);
172-
173171
bool runOnFunction(Function &F) override;
174172

175173
bool isFpMadEnabled() const {
@@ -3671,16 +3669,6 @@ void GenXPatternMatch::visitURem(BinaryOperator &I) {
36713669
return decomposeURemPow2(I);
36723670
}
36733671

3674-
// Clean up 'freeze' instances once dependent w/a's have been resolved.
3675-
void GenXPatternMatch::visitFreezeInst(FreezeInst &I) {
3676-
if (I.use_empty())
3677-
return;
3678-
3679-
Value *Op = I.getOperand(0);
3680-
I.replaceAllUsesWith(Op);
3681-
Changed = true;
3682-
}
3683-
36843672
// Decompose predicate operand for large vector selects.
36853673
bool GenXPatternMatch::decomposeSelect(Function *F) {
36863674
const GenXSubtarget *ST = &getAnalysis<TargetPassConfig>()

IGC/VectorCompiler/lib/GenXCodeGen/GenXTargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ void initializeGenXPasses(PassRegistry &registry) {
246246
initializeGenXLCECalculationPass(registry);
247247
initializeGenXFloatControlPass(registry);
248248
initializeGenXCountIndirectStatelessPass(registry);
249+
initializeGenXUnfreezePass(registry);
249250
// WRITE HERE MORE PASSES IF IT'S NEEDED;
250251
}
251252

@@ -504,6 +505,8 @@ bool GenXTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
504505
vc::addPass(PM, PassConfig);
505506
const GenXBackendConfig &BackendConfig = PassConfig->getBackendConfig();
506507

508+
vc::addPass(PM, createGenXUnfreezePass());
509+
507510
vc::addPass(PM, createGenXInitBiFConstantsPass());
508511
vc::addPass(PM, createGenXFixInvalidFuncNamePass());
509512

IGC/VectorCompiler/lib/GenXCodeGen/GenXTargetMachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ void initializeGenXDetectPointerArgPass(PassRegistry &);
271271
void initializeGenXLCECalculationPass(PassRegistry &);
272272
void initializeGenXFloatControlPass(PassRegistry &);
273273
void initializeGenXCountIndirectStatelessPass(PassRegistry &);
274+
void initializeGenXUnfreezePass(PassRegistry &);
274275
} // End llvm namespace
275276

276277
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2025 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#include "GenX.h"
10+
11+
#include "llvm/IR/InstVisitor.h"
12+
13+
#define DEBUG_TYPE "GENX_UNFREEZE"
14+
15+
using namespace llvm;
16+
17+
namespace {
18+
class GenXUnfreeze : public FunctionPass, public InstVisitor<GenXUnfreeze> {
19+
bool Changed = false;
20+
21+
public:
22+
static char ID;
23+
explicit GenXUnfreeze() : FunctionPass(ID) {}
24+
25+
StringRef getPassName() const override { return "GenX unfreeze"; }
26+
27+
void getAnalysisUsage(AnalysisUsage &AU) const override {
28+
AU.setPreservesCFG();
29+
}
30+
31+
void visitFreezeInst(FreezeInst &FI);
32+
33+
bool runOnFunction(Function &F) override;
34+
};
35+
36+
} // namespace
37+
38+
char GenXUnfreeze::ID = 0;
39+
40+
namespace llvm {
41+
void initializeGenXUnfreezePass(PassRegistry &);
42+
} // namespace llvm
43+
44+
INITIALIZE_PASS_BEGIN(GenXUnfreeze, "GenXUnfreeze", "GenXUnfreeze", false,
45+
false)
46+
INITIALIZE_PASS_END(GenXUnfreeze, "GenXUnfreeze", "GenXUnfreeze", false, false)
47+
48+
FunctionPass *llvm::createGenXUnfreezePass() {
49+
initializeGenXUnfreezePass(*PassRegistry::getPassRegistry());
50+
return new GenXUnfreeze();
51+
}
52+
53+
void GenXUnfreeze::visitFreezeInst(FreezeInst &FI) {
54+
if (FI.use_empty())
55+
return;
56+
auto *V = FI.getOperand(0);
57+
FI.replaceAllUsesWith(V);
58+
FI.eraseFromParent();
59+
Changed = true;
60+
}
61+
62+
bool GenXUnfreeze::runOnFunction(Function &F) {
63+
visit(F);
64+
return Changed;
65+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023-2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: %opt %use_old_pass_manager% -GenXUnfreeze -march=genx64 -mcpu=XeLP -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s
10+
11+
; CHECK-NOT: freeze
12+
13+
define spir_kernel void @test(i32 %arg) {
14+
%w = add i32 %arg, undef
15+
%x = freeze i32 %w
16+
%y = add i32 %w, %w ; undef
17+
%z = add i32 %x, %x ; even number because all uses of %x observe
18+
; the same value
19+
%x2 = freeze i32 %w
20+
%cmp = icmp eq i32 %x, %x2 ; can be true or false
21+
22+
; example with vectors
23+
%v = add <2 x i32> <i32 undef, i32 poison>, zeroinitializer
24+
%a = extractelement <2 x i32> %v, i32 0 ; undef
25+
%b = extractelement <2 x i32> %v, i32 1 ; poison
26+
%add = add i32 %a, %a ; undef
27+
28+
%v.fr = freeze <2 x i32> %v ; element-wise freeze
29+
%d = extractelement <2 x i32> %v.fr, i32 0 ; not undef
30+
%add.f = add i32 %d, %d ; even number
31+
32+
ret void
33+
}

IGC/VectorCompiler/test/PatternMatch/freeze-patt.ll

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)