Skip to content

Commit ebbb4a8

Browse files
paigealegfxbot
authored andcommitted
Adding new pattern for icmp to catch when we are comparing constant int's tht have 0's in their first 32 bits. Essentially we turn the icmp from a 64bit compare to a 32bit compare instruction
Change-Id: I76f588f4e7e454d7c094d4e019a9c76c332bca45
1 parent dd82a0c commit ebbb4a8

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,12 +1180,36 @@ void GenSpecificPattern::visitBinaryOperator(BinaryOperator &I)
11801180

11811181
void GenSpecificPattern::visitCmpInst(CmpInst &I)
11821182
{
1183-
CodeGenContext* pCtx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
1184-
if (pCtx->m_DriverInfo.IgnoreNan())
1183+
using namespace llvm::PatternMatch;
1184+
CmpInst::Predicate Pred;
1185+
Value *Val1;
1186+
uint64_t const_int1 = 0, const_int2 = 0;
1187+
auto cmp_pattern = m_Cmp(Pred,
1188+
m_And(m_Value(Val1), m_ConstantInt(const_int1)), m_ConstantInt(const_int2));
1189+
1190+
if (match(&I, cmp_pattern) &&
1191+
(const_int1 << 32) == 0 &&
1192+
(const_int2 << 32) == 0 &&
1193+
Val1->getType()->isIntegerTy(64))
1194+
{
1195+
llvm::IRBuilder<> builder(&I);
1196+
VectorType* vec2 = VectorType::get(builder.getInt32Ty(), 2);
1197+
Value* BC = builder.CreateBitCast(Val1, vec2);
1198+
Value* EE = builder.CreateExtractElement(BC, builder.getInt32(1));
1199+
Value* AI = builder.CreateAnd(EE, builder.getInt32(const_int1 >> 32));
1200+
Value* new_Val = builder.CreateICmp(Pred, AI, builder.getInt32(const_int2 >> 32));
1201+
I.replaceAllUsesWith(new_Val);
1202+
I.eraseFromParent();
1203+
}
1204+
else
11851205
{
1186-
if (I.getPredicate() == CmpInst::FCMP_ORD)
1206+
CodeGenContext* pCtx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
1207+
if (pCtx->m_DriverInfo.IgnoreNan())
11871208
{
1188-
I.replaceAllUsesWith(ConstantInt::getTrue(I.getType()));
1209+
if (I.getPredicate() == CmpInst::FCMP_ORD)
1210+
{
1211+
I.replaceAllUsesWith(ConstantInt::getTrue(I.getType()));
1212+
}
11891213
}
11901214
}
11911215
}

0 commit comments

Comments
 (0)