Skip to content

Commit 92d23bc

Browse files
tuStromaigcbot
authored andcommitted
Add ZExt instruction on Cmp bool promotion
After promoting Cmp instructions of type i1 all uses are replaced with extended to i8 value
1 parent 4614c6c commit 92d23bc

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

IGC/AdaptorOCL/preprocess_spvir/PromoteBools.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ Value* PromoteBools::getOrCreatePromotedValue(Value* value)
412412
{
413413
newValue = promoteICmp(icmp);
414414
}
415+
else if (auto fcmp = dyn_cast<FCmpInst>(value))
416+
{
417+
newValue = promoteFCmp(fcmp);
418+
}
415419
else if (auto inlineAsm = dyn_cast<InlineAsm>(value))
416420
{
417421
newValue = promoteInlineAsm(inlineAsm);
@@ -481,6 +485,17 @@ Value* PromoteBools::getOrCreatePromotedValue(Value* value)
481485
}
482486
}
483487

488+
if (typeNeedsPromotion(newValue->getType()))
489+
{
490+
if (auto instruction = dyn_cast<Instruction>(newValue))
491+
{
492+
ZExtInst* zext = new ZExtInst(newValue, getOrCreatePromotedType(newValue->getType()), "");
493+
zext->insertAfter(instruction);
494+
if (newValue == value)
495+
return zext;
496+
}
497+
}
498+
484499
if (newValue != value)
485500
{
486501
promotedValuesCache[value] = newValue;
@@ -1009,6 +1024,35 @@ ICmpInst* PromoteBools::promoteICmp(ICmpInst* icmp)
10091024
return newICmp;
10101025
}
10111026

1027+
FCmpInst* PromoteBools::promoteFCmp(FCmpInst* fcmp)
1028+
{
1029+
if (!fcmp)
1030+
{
1031+
return nullptr;
1032+
}
1033+
1034+
auto op0 = fcmp->getOperand(0);
1035+
auto op1 = fcmp->getOperand(1);
1036+
1037+
if (!wasPromotedAnyOf(fcmp->operands()) && !typeNeedsPromotion(op0->getType()))
1038+
{
1039+
return fcmp;
1040+
}
1041+
1042+
auto promotedOp0 = convertI1ToI8(getOrCreatePromotedValue(op0), fcmp);
1043+
auto promotedOp1 = convertI1ToI8(getOrCreatePromotedValue(op1), fcmp);
1044+
1045+
auto newFCmp = new FCmpInst(
1046+
fcmp,
1047+
fcmp->getPredicate(),
1048+
promotedOp0,
1049+
promotedOp1,
1050+
""
1051+
);
1052+
newFCmp->setDebugLoc(fcmp->getDebugLoc());
1053+
return newFCmp;
1054+
}
1055+
10121056
InlineAsm* PromoteBools::promoteInlineAsm(InlineAsm* inlineAsm)
10131057
{
10141058
if (!inlineAsm || !typeNeedsPromotion(inlineAsm->getFunctionType()))

IGC/AdaptorOCL/preprocess_spvir/PromoteBools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ namespace IGC
9393
llvm::ExtractValueInst* promoteExtractValue(llvm::ExtractValueInst* extractValue);
9494
llvm::GetElementPtrInst* promoteGetElementPtr(llvm::GetElementPtrInst* getElementPtr);
9595
llvm::ICmpInst* promoteICmp(llvm::ICmpInst* icmp);
96+
llvm::FCmpInst* promoteFCmp(llvm::FCmpInst* fcmp);
9697
llvm::InlineAsm* promoteInlineAsm(llvm::InlineAsm* inlineAsm);
9798
llvm::InsertValueInst* promoteInsertValue(llvm::InsertValueInst* insertValue);
9899
llvm::LoadInst* promoteLoad(llvm::LoadInst* load);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt -igc-promote-bools -S %s -o %t.ll
10+
; RUN: FileCheck %s --input-file=%t.ll
11+
12+
define spir_kernel void @fcmp() {
13+
%C3 = fcmp oeq float zeroinitializer, zeroinitializer
14+
store i1 %C3, i1* null, align 1
15+
ret void
16+
}
17+
18+
; CHECK-LABEL: define spir_kernel void @fcmp()
19+
20+
; CHECK: [[TMP0:%.*]] = fcmp oeq float
21+
; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[TMP0]] to i8
22+
; CHECK-NEXT: store i8 [[TMP1]], i8* null, align 1

0 commit comments

Comments
 (0)