Skip to content

Commit 8091063

Browse files
iwwuZuul
authored andcommitted
Support Predicate Add with fsub, Part 3
Change-Id: Id5c97cf811462ef35cafb38b53edd0aa5ff87860
1 parent a16125c commit 8091063

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ namespace IGC
964964
case Instruction::FSub:
965965
match = MatchFrc(I) ||
966966
MatchLrp(I) ||
967+
MatchPredAdd(I) ||
967968
MatchMad(I) ||
968969
MatchAbsNeg(I) ||
969970
MatchModifier(I);
@@ -1699,8 +1700,7 @@ namespace IGC
16991700
}
17001701
}
17011702

1702-
// FSub is not supported currently due to addional instruction requirement
1703-
assert(I.getOpcode() == Instruction::FAdd);
1703+
assert(I.getOpcode() == Instruction::FAdd || I.getOpcode() == Instruction::FSub);
17041704
for (uint iAdd = 0; iAdd < 2 && !found; iAdd++)
17051705
{
17061706
Value* src = I.getOperand(iAdd);
@@ -1740,17 +1740,32 @@ namespace IGC
17401740
continue;
17411741
}
17421742

1743+
// % 97 = select i1 %res_s48, float 1.000000e+00, float 0.000000e+00
1744+
// %102 = fmul fast float %97 %98
1745+
1746+
// case 1 (add)
17431747
// Before match
1744-
// % 97 = select i1 %res_s48, float 1.000000e+00, float 0.000000e+00
1745-
// %102 = fmul fast float %97 %98
1746-
// %105 = fadd %102 %103
1748+
// %105 = fadd %102 %103
1749+
// After match
1750+
// %105 = %103
1751+
// (%res_s48) %105 = fadd %105 %98
17471752

1753+
// case 2 (fsub match @ iAdd = 0)
1754+
// Before match
1755+
// %105 = fsub %102 %103
17481756
// After match
1749-
// %105 = %103
1750-
// (%res_s48) %105 = fadd %103 %98
1757+
// %105 = -%103
1758+
// (%res_s48) %105 = fadd %105 %98
17511759

1752-
// sources[0]: add operand (i.e. %103 above)
1753-
// sources[1]: mul operand (i.e. %98 above)
1760+
// case 3 (fsub match @ iAdd = 1)
1761+
// Before match
1762+
// %105 = fsub %103 %102
1763+
// After match
1764+
// %105 = %103
1765+
// (%res_s48) %98 = fadd %105 -%98
1766+
1767+
// sources[0]: store add operand (i.e. %103 above)
1768+
// sources[1]: store mul operand (i.e. %98 above)
17541769

17551770
sources[0] = I.getOperand(1 ^ iAdd);
17561771
sources[1] = mul->getOperand(1 ^ iMul);
@@ -1760,6 +1775,11 @@ namespace IGC
17601775
GetModifier(*sources[1], src_mod[1], sources[1]);
17611776
GetModifier(*pred, pred_mod, pred);
17621777

1778+
if (I.getOpcode() == Instruction::FSub)
1779+
{
1780+
src_mod[iAdd] = CombineModifier(EMOD_NEG, src_mod[iAdd]);
1781+
}
1782+
17631783
found = true;
17641784
break;
17651785
} // if (llvm::SelectInst* selInst = dyn_cast<SelectInst>(mul->getOperand(iMul)))

0 commit comments

Comments
 (0)