Skip to content

Commit b61d0d6

Browse files
igorban-inteligcbot
authored andcommitted
Lower null-cast patterns
Match `addrspacecast (Ty1 null to Ty2)` pattern to `null`
1 parent cf5c435 commit b61d0d6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,17 @@ bool GenXPatternMatch::placeConstants(Function *F) {
41684168
continue;
41694169
if (opMustBeConstant(Inst, i))
41704170
continue;
4171+
4172+
// Match `addrspacecast (Ty1 null to Ty2)` pattern to `null`
4173+
if (auto *Const = dyn_cast<ConstantExpr>(C); Const && Const->isCast()) {
4174+
auto *NullVal = dyn_cast<Constant>(Const->getOperand(0));
4175+
if (NullVal && NullVal->isNullValue()) {
4176+
auto *Ty = cast<PointerType>(Const->getType());
4177+
auto *NewConst = llvm::ConstantPointerNull::get(Ty);
4178+
Inst->setOperand(i, NewConst);
4179+
Changed = true;
4180+
}
4181+
}
41714182
auto Ty = C->getType();
41724183
if (!Ty->isVectorTy() || C->getSplatValue())
41734184
continue;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,12 @@ case4:
8888

8989
declare <16 x i32> @llvm.genx.wrregionf.v16i32.v1i32.i16.i1(<16 x i32>, <1 x i32>, i32, i32, i32, i16, i32, i1)
9090
declare <16 x i32> @llvm.genx.wrregionf.v16i32.v2i32.i16.v2i1(<16 x i32>, <2 x i32>, i32, i32, i32, i16, i32, <2 x i1>)
91-
declare <16 x i32> @llvm.genx.wrregionf.v16i32.v1i32.i16.v16i1(<16 x i32>, <1 x i32>, i32, i32, i32, i16, i32, <16 x i1>)
91+
declare <16 x i32> @llvm.genx.wrregionf.v16i32.v1i32.i16.v16i1(<16 x i32>, <1 x i32>, i32, i32, i32, i16, i32, <16 x i1>)
92+
93+
; CHECK-LABEL: test_addrspacecast
94+
define i1 @test_addrspacecast(i64 %in) {
95+
; CHECK: %res = icmp ne [17 x i8] addrspace(1)* %b, null
96+
%b = inttoptr i64 %in to [17 x i8] addrspace(1)*
97+
%res = icmp ne [17 x i8] addrspace(1)* %b, addrspacecast ([17 x i8] addrspace(4)* null to [17 x i8] addrspace(1)*)
98+
ret i1 %res
99+
}

0 commit comments

Comments
 (0)