Skip to content

Commit 5ebf9e5

Browse files
krystian-andrzejewskisys_zuul
authored andcommitted
Add pattern match to emit integer trunc instruction with saturation.
Fix definition of opcodes - advertise support for sat modifier. Change-Id: I59aa79299d120e6e5cf0c20dec0ce8ec4c2f3ef3
1 parent e0bc134 commit 5ebf9e5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,15 @@ namespace IGC
31653165
}
31663166
};
31673167

3168+
struct IntegerSatTruncPattern : public Pattern {
3169+
SSource src;
3170+
bool isSigned;
3171+
virtual void Emit(EmitPass* pass, const DstModifier& dstMod)
3172+
{
3173+
pass->EmitIntegerTruncWithSat(isSigned, isSigned, src, dstMod);
3174+
}
3175+
};
3176+
31683177
bool match = false;
31693178
llvm::Value* source = nullptr;
31703179
bool isUnsigned = false;
@@ -3193,6 +3202,15 @@ namespace IGC
31933202
satPattern->pattern = Match(*sourceInst);
31943203
AddPattern(satPattern);
31953204
}
3205+
else if (llvm::TruncInst* truncInst = llvm::dyn_cast<llvm::TruncInst>(source);
3206+
truncInst)
3207+
{
3208+
match = true;
3209+
IntegerSatTruncPattern* satPattern = new (m_allocator) IntegerSatTruncPattern();
3210+
satPattern->isSigned = !isUnsigned;
3211+
satPattern->src = GetSource(truncInst->getOperand(0), !isUnsigned, false);
3212+
AddPattern(satPattern);
3213+
}
31963214
else if (llvm::GenIntrinsicInst * genIsaInst = llvm::dyn_cast<llvm::GenIntrinsicInst>(source);
31973215
genIsaInst &&
31983216
(genIsaInst->getIntrinsicID() == llvm::GenISAIntrinsic::ID::GenISA_dp4a_ss ||

IGC/Compiler/CISACodeGen/opCode.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ DECLARE_OPCODE(FCmp, Instruction, llvm_fcmp, true, false, false, false, false, f
8787
DECLARE_OPCODE(Br, Instruction, llvm_branch, false, false, false, false, false, false, false)
8888
DECLARE_OPCODE(PHI, Instruction, llvm_phi, false, false, false, false, false, false, false)
8989
DECLARE_OPCODE(ICmp, Instruction, llvm_icmp, true, false, false, false, false, false, false)
90-
DECLARE_OPCODE(Add, Instruction, llvm_add, true, false, true, true, false, false, true)
90+
DECLARE_OPCODE(Add, Instruction, llvm_add, true, true, true, true, false, false, true)
9191
DECLARE_OPCODE(Sub, Instruction, llvm_sub, true, false, true, true, false, false, false)
9292
DECLARE_OPCODE(UIToFP, Instruction, llvm_uitofp, false, true, true, true, false, false, false)
9393
DECLARE_OPCODE(SIToFP, Instruction, llvm_sitofp, true, true, true, true, false, false, false)
@@ -136,6 +136,10 @@ DECLARE_OPCODE(GenISA_f32tof16_rtz, GenISAIntrinsic, llvm_f32tof16_rtz, true, fa
136136
DECLARE_OPCODE(fabs, Intrinsic, llvm_fabs, false, false, true, false, true, false, false)
137137
DECLARE_OPCODE(GenISA_fsat, GenISAIntrinsic, llvm_fsat, true, false, true, true, true, false, false)
138138
DECLARE_OPCODE(canonicalize, Intrinsic, llvm_canonicalize, true, true, true, true, false, false, false)
139+
DECLARE_OPCODE(GenISA_dp4a_ss, GenISAIntrinsic, llvm_dp4a_ss, false, true, true, true, false, false, false)
140+
DECLARE_OPCODE(GenISA_dp4a_uu, GenISAIntrinsic, llvm_dp4a_uu, false, true, true, true, false, false, false)
141+
DECLARE_OPCODE(GenISA_dp4a_su, GenISAIntrinsic, llvm_dp4a_su, false, true, true, true, false, false, false)
142+
DECLARE_OPCODE(GenISA_dp4a_us, GenISAIntrinsic, llvm_dp4a_us, false, true, true, true, false, false, false)
139143

140144
// GS Intrinsics
141145
DECLARE_OPCODE(GenISA_OUTPUTGS, GenISAIntrinsic, llvm_output_gs, false, false, false, false, false, false, false)

0 commit comments

Comments
 (0)