Skip to content

Commit aaeb7d7

Browse files
lwesierssys_zuul
authored andcommitted
Fix FNeg for the vectors type.
Change-Id: I91bfea8c72345084a5a1648fd1aee92f8aafe336
1 parent 43ba411 commit aaeb7d7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,24 @@ void GenSpecificPattern::visitFNeg(llvm::UnaryOperator& I)
23022302

23032303
IRBuilder<> builder(&I);
23042304

2305-
Value* fsub = builder.CreateFSub(ConstantFP::get(I.getType(), 0.0f), I.getOperand(0));
2305+
Value* fsub = nullptr;
2306+
2307+
if (!I.getType()->isVectorTy())
2308+
{
2309+
fsub = builder.CreateFSub(ConstantFP::get(I.getType(), 0.0f), I.getOperand(0));
2310+
}
2311+
else
2312+
{
2313+
uint32_t vectorSize = I.getType()->getVectorNumElements();
2314+
fsub = llvm::UndefValue::get(I.getType());
2315+
2316+
for (int i = 0; i < vectorSize; ++i)
2317+
{
2318+
Value* extract = builder.CreateExtractElement(I.getOperand(0), i);
2319+
Value* extract_fsub = builder.CreateFSub(ConstantFP::get(extract->getType(), 0.0f), extract);
2320+
fsub = builder.CreateInsertElement(fsub, extract_fsub, i);
2321+
}
2322+
}
23062323

23072324
I.replaceAllUsesWith(fsub);
23082325
}

0 commit comments

Comments
 (0)