[llvm] [WIP] [AMDGPU] [GlobalIsel] Combine Fmul with Select into ldexp instruction. (PR #120104)
Vikash Gupta via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 16 22:36:44 PST 2024
================
@@ -445,3 +445,75 @@ void AMDGPUCombinerHelper::applyExpandPromotedF16FMed3(MachineInstr &MI,
Builder.buildFMinNumIEEE(MI.getOperand(0), B1, C1);
MI.eraseFromParent();
}
+
+bool AMDGPUCombinerHelper::matchCombineFmulWithSelectToLdexp(
+ MachineInstr &MI, MachineInstr &Sel,
+ std::function<void(MachineIRBuilder &)> &MatchInfo) {
+ assert(MI.getOpcode() == TargetOpcode::G_FMUL);
+ assert(Sel.getOpcode() == TargetOpcode::G_SELECT);
+
+ Register Dst = MI.getOperand(0).getReg();
+ LLT DestTy = MRI.getType(Dst);
+ LLT ScalarDestTy = DestTy.getScalarType();
+
+ if ((ScalarDestTy == LLT::float64() || ScalarDestTy == LLT::float32() ||
+ ScalarDestTy == LLT::float16()) &&
+ (MRI.hasOneNonDBGUse(Sel.getOperand(0).getReg()))) {
+ Register SelectCond = Sel.getOperand(1).getReg();
+ Register SelectTrue = Sel.getOperand(2).getReg();
+ Register SelectFalse = Sel.getOperand(3).getReg();
+
+ const auto SelectTrueCst =
+ DestTy.isVector()
+ ? getFConstantSplat(SelectTrue, MRI, /* allowUndef */ true)
+ : getFConstantVRegValWithLookThrough(SelectTrue, MRI);
+ if (!SelectTrueCst)
+ return false;
+ const auto SelectFalseCst =
+ DestTy.isVector()
+ ? getFConstantSplat(SelectFalse, MRI, /* allowUndef */ true)
+ : getFConstantVRegValWithLookThrough(SelectFalse, MRI);
----------------
vg0204 wrote:
> After looking into isConstOrConstSplatFP's counter part for integer in globalIsel i.e. **_isConstantOrConstantSplatVector_**, what I wrote can be considered the equivalent, so if it requires, I can turn it into a utility function as isConstOrConstSplatFP for globalIsel, if you can review that!!
I think would be this better as separate PR as well!
https://github.com/llvm/llvm-project/pull/120104
More information about the llvm-commits
mailing list