[llvm] [GISel][AArch64][AMDGPU][RISCV] Canonicalize (sub X, C) -> (add X, -C) (PR #114309)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 30 23:00:24 PDT 2024
================
@@ -2041,6 +2041,28 @@ void CombinerHelper::applyCombineMulToShl(MachineInstr &MI,
Observer.changedInstr(MI);
}
+bool CombinerHelper::matchCombineSubToAdd(MachineInstr &MI,
+ BuildFnTy &MatchInfo) {
+ GSub &Sub = cast<GSub>(MI);
+
+ LLT Ty = MRI.getType(Sub.getReg(0));
+
+ if (!isLegalOrBeforeLegalizer({TargetOpcode::G_ADD, {Ty}}))
+ return false;
+
+ APInt Imm = getIConstantFromReg(Sub.getRHSReg(), MRI);
+
+ MatchInfo = [=, &MI](MachineIRBuilder &B) {
+ auto NegCst = B.buildConstant(Ty, -Imm);
----------------
topperc wrote:
I don't know what you mean. I checked G_CONSTANT in the .td file like you told me to.
https://github.com/llvm/llvm-project/pull/114309
More information about the llvm-commits
mailing list