Skip to content

Commit 0381a4d

Browse files
bgajdaINTCsys_zuul
authored andcommitted
Extend constant pool for select (same rules as other DF/QW instr.)
Change-Id: I1af172cb70babd5576b06a314c2a833d90f411e6
1 parent cd53fb1 commit 0381a4d

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,8 +3240,12 @@ void EmitPass::Select(const SSource sources[3], const DstModifier& modifier)
32403240
{
32413241
assert(modifier.flag == nullptr && sources[0].mod == EMOD_NONE);
32423242
CVariable* flag = GetSrcVariable(sources[0]);
3243-
CVariable* src0 = GetSrcVariable(sources[1]);;
3244-
CVariable* src1 = GetSrcVariable(sources[2]);;
3243+
3244+
bool fromConstantPool = sources[1].fromConstantPool;
3245+
CVariable* src0 = GetSrcVariable(sources[1], fromConstantPool);
3246+
3247+
fromConstantPool = sources[2].fromConstantPool;
3248+
CVariable* src1 = GetSrcVariable(sources[2], fromConstantPool);
32453249

32463250
SetSourceModifiers(0, sources[1]);
32473251
SetSourceModifiers(1, sources[2]);

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,18 +2760,14 @@ namespace IGC
27602760
pattern->sources[1] = GetSource(I.getOperand(1), supportModifer, supportRegioning);
27612761
}
27622762

2763-
if (nbSources > 1 && (I.getType()->isDoubleTy() || I.getType()->isIntegerTy(64)))
2763+
if (nbSources > 1)
27642764
{
27652765
// add df imm to constant pool for binary/ternary inst
2766-
// we do 64-bit int imm biggerthan 32 bits, since smaller may fit in D/W
2766+
// we do 64-bit int imm bigger than 32 bits, since smaller may fit in D/W
27672767
for (int i = 0, numSrc = (int)nbSources; i < numSrc; ++i)
27682768
{
27692769
Value* op = I.getOperand(i);
2770-
bool isDF = isa<ConstantFP>(op);
2771-
auto ci = dyn_cast<ConstantInt>(op);
2772-
bool isBigQW = ci && !ci->getValue().isNullValue() && !ci->getValue().isSignedIntN(32);
2773-
2774-
if (isDF || isBigQW)
2770+
if (isCandidateForConstantPool(op))
27752771
{
27762772
AddToConstantPool(I.getParent(), op);
27772773
pattern->sources[i].fromConstantPool = true;
@@ -2978,6 +2974,20 @@ namespace IGC
29782974
pattern->sources[0] = GetSource(I.getCondition(), false, false);
29792975
pattern->sources[1] = GetSource(I.getTrueValue(), true, false);
29802976
pattern->sources[2] = GetSource(I.getFalseValue(), true, false);
2977+
2978+
// try to add to constant pool whatever possible.
2979+
if (isCandidateForConstantPool(I.getTrueValue()))
2980+
{
2981+
AddToConstantPool(I.getParent(), I.getTrueValue());
2982+
pattern->sources[1].fromConstantPool = true;
2983+
}
2984+
2985+
if (isCandidateForConstantPool(I.getFalseValue()))
2986+
{
2987+
AddToConstantPool(I.getParent(), I.getFalseValue());
2988+
pattern->sources[2].fromConstantPool = true;
2989+
}
2990+
29812991
AddPattern(pattern);
29822992
return true;
29832993
}
@@ -3425,16 +3435,10 @@ namespace IGC
34253435
}
34263436
pattern->sources[i] = GetSource(src, mod, false);
34273437

3428-
if (src->getType()->isIntegerTy(64))
3438+
if (isCandidateForConstantPool(src))
34293439
{
3430-
auto ci = dyn_cast<ConstantInt>(src);
3431-
bool isBigQW = ci && !ci->getValue().isNullValue() && !ci->getValue().isSignedIntN(32);
3432-
3433-
if (isBigQW)
3434-
{
3435-
AddToConstantPool(I.getParent(), src);
3436-
pattern->sources[i].fromConstantPool = true;
3437-
}
3440+
AddToConstantPool(I.getParent(), src);
3441+
pattern->sources[i].fromConstantPool = true;
34383442
}
34393443

34403444

@@ -4226,6 +4230,14 @@ namespace IGC
42264230
return found;
42274231
}
42284232

4233+
bool isCandidateForConstantPool(llvm::Value * val)
4234+
{
4235+
auto ci = dyn_cast<ConstantInt>(val);
4236+
bool isBigQW = ci && !ci->getValue().isNullValue() && !ci->getValue().isSignedIntN(32);
4237+
bool isDF = val->getType()->isDoubleTy();
4238+
return (isBigQW || isDF);
4239+
};
4240+
42294241
uint CodeGenPatternMatch::GetBlockId(llvm::BasicBlock* block)
42304242
{
42314243
auto it = m_blockMap.find(block);

IGC/Compiler/CISACodeGen/PatternMatchPass.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ namespace IGC
321321
bool isSat(llvm::Instruction* sat, llvm::Value*& source);
322322
bool isOne(llvm::Value* zero);
323323
bool isMinOrMax(llvm::Value* inst, llvm::Value*& source0, llvm::Value*& source1, bool& isMin, bool& isUnsigned);
324+
bool isCandidateForConstantPool(llvm::Value * val);
324325
e_modifier CombineModifier(e_modifier mod1, e_modifier mod2);
325326

326327
static uint GetNbSources(llvm::Instruction& v)

0 commit comments

Comments
 (0)