[all-commits] [llvm/llvm-project] 6e071a: [RISCV] Rewrite ADD to SUB to reuse a materialized...
Pengcheng Wang via All-commits
all-commits at lists.llvm.org
Mon Sep 14 02:26:20 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 6e071ab17caa0058a83cdd1580026259fdaecb4f
https://github.com/llvm/llvm-project/commit/6e071ab17caa0058a83cdd1580026259fdaecb4f
Author: Pengcheng Wang <wangpengcheng.pp at bytedance.com>
Date: 2026-09-14 (Mon, 14 Sep 2026)
Changed paths:
M llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
M llvm/test/CodeGen/RISCV/add-imm64-to-sub.ll
Log Message:
-----------
[RISCV] Rewrite ADD to SUB to reuse a materialized negated constant (#221027)
When an ADD needs a large constant whose negation is already
present in the DAG, rewrite (add X, C) into (sub X, -C) so both
share one materialization of -C instead of building it twice.
selectNegImm already does a related rewrite, but only when -C is
strictly cheaper than C and during instruction selection, where the
sibling constant may already have been selected into instructions.
Do it in PreprocessISelDAG instead, before selection, while both are
still ConstantSDNodes that getConstant can unique together. The
rewrite only fires when -C is no more expensive than C and a node
holding -C already exists, so it never adds a materialization.
Fixes https://github.com/llvm/llvm-project/issues/220555
Assisted-by: TRAE CLI (Opus 4.8)
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list