@@ -310,6 +310,9 @@ void ScalarizeFunction::dispatchInstructionToScalarize(Instruction* I)
310
310
311
311
switch (I->getOpcode ())
312
312
{
313
+ case Instruction::FNeg:
314
+ scalarizeInstruction (dyn_cast<UnaryOperator>(I));
315
+ break ;
313
316
case Instruction::Add:
314
317
case Instruction::Sub:
315
318
case Instruction::Mul:
@@ -415,6 +418,55 @@ void ScalarizeFunction::recoverNonScalarizableInst(Instruction* Inst)
415
418
}
416
419
}
417
420
421
+ void ScalarizeFunction::scalarizeInstruction (UnaryOperator* UI)
422
+ {
423
+ V_PRINT (scalarizer, " \t\t Unary instruction\n " );
424
+ IGC_ASSERT_MESSAGE (UI, " instruction type dynamic cast failed" );
425
+ IGCLLVM::FixedVectorType* instType = dyn_cast<IGCLLVM::FixedVectorType>(UI->getType ());
426
+ // Only need handling for vector binary ops
427
+ if (!instType) return ;
428
+
429
+ // Prepare empty SCM entry for the instruction
430
+ SCMEntry* newEntry = getSCMEntry (UI);
431
+
432
+ // Get additional info from instruction
433
+ unsigned numElements = int_cast<unsigned >(instType->getNumElements ());
434
+
435
+ // Obtain scalarized argument
436
+ SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH>operand0;
437
+ bool op0IsConst;
438
+
439
+ obtainScalarizedValues (operand0, &op0IsConst, UI->getOperand (0 ), UI);
440
+
441
+ // If argument is constant, don't bother Scalarizing inst
442
+ if (op0IsConst) return ;
443
+
444
+ // Generate new (scalar) instructions
445
+ SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH>newScalarizedInsts;
446
+ newScalarizedInsts.resize (numElements);
447
+ for (unsigned dup = 0 ; dup < numElements; dup++)
448
+ {
449
+ Value* Val = UnaryOperator::Create (
450
+ UI->getOpcode (),
451
+ operand0[dup],
452
+ UI->getName (),
453
+ UI
454
+ );
455
+ if (UnaryOperator* UO = dyn_cast<UnaryOperator>(Val)) {
456
+ // Copy fast math flags if any.
457
+ if (isa<FPMathOperator>(UO))
458
+ UO->setFastMathFlags (UI->getFastMathFlags ());
459
+ }
460
+ newScalarizedInsts[dup] = Val;
461
+ }
462
+
463
+ // Add new value/s to SCM
464
+ updateSCMEntryWithValues (newEntry, &(newScalarizedInsts[0 ]), UI, true );
465
+
466
+ // Remove original instruction
467
+ m_removedInsts.insert (UI);
468
+ }
469
+
418
470
void ScalarizeFunction::scalarizeInstruction (BinaryOperator* BI)
419
471
{
420
472
V_PRINT (scalarizer, " \t\t Binary instruction\n " );
0 commit comments