[llvm] [GlobalIsel] Transform build_vector(binop(_, C), ...) -> binop(bv, constant bv) (PR #73577)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 03:00:38 PST 2023
================
@@ -6224,3 +6224,89 @@ void CombinerHelper::applyCommuteBinOpOperands(MachineInstr &MI) {
MI.getOperand(2).setReg(LHSReg);
Observer.changedInstr(MI);
}
+
+// Transform build_vector of binop(_,C) -> binop(BV, constant BV).
+bool CombinerHelper::matchBuildVectorToBinOp(MachineInstr &MI,
+ BuildFnTy &MatchInfo) {
+ GBuildVector *BuildVector = cast<GBuildVector>(&MI);
+ Register Dst = BuildVector->getReg(0);
+
+ unsigned NumOfSources = BuildVector->getNumSources();
+ if (NumOfSources == 1)
+ return false;
+
+ LLT ElementTy = MRI.getType(BuildVector->getSourceReg(0));
+ LLT BVTy = MRI.getType(BuildVector->getReg(0));
+
+ MachineInstr *FirstDef = MRI.getVRegDef(BuildVector->getSourceReg(0));
+ const unsigned Opcode = FirstDef->getOpcode();
+ SmallVector<Register> LHS;
+
+ if (isa<GIntBinOp>(FirstDef)) {
+ SmallVector<APInt> RHS;
----------------
tschuett wrote:
There is:
https://github.com/llvm/llvm-project/blob/a05c23fdcf45c39e31931a68f2352a7eff5333a4/llvm/include/llvm/CodeGen/GlobalISel/Utils.h#L196
I thought about that, but it will fail with `buildBuildVectorConstant` . It sometimes must be floats and sometimes it must be integers.
https://github.com/llvm/llvm-project/pull/73577
More information about the llvm-commits
mailing list