[llvm] [RISCV] Combine (ADDI (ADDI X, C1), C2) -> (ADDI X, C1+C2) (PR #157416)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 09:49:58 PDT 2025
topperc wrote:
> I found three patterns:
>
> 1. [e.g. 23456b036ecbc7d0](https://github.com/dtcxzyw/llvm-codegen-benchmark/blob/24627cd223f7ca9e686a898658cabba4d4339e7e/result/rvb23u64/23456b036ecbc7d0.S)
> This can be addressed by the change in RISCVISelLowering.cpp.
> 2. [e.g. d1e7a5db560b32a5](https://github.com/dtcxzyw/llvm-codegen-benchmark/blob/24627cd223f7ca9e686a898658cabba4d4339e7e/result/rvb23u64/d1e7a5db560b32a5.S)
> Similar, but the inner ADDI is ADDIW until riscv-opt-w-instrs. How to handle?
> 3. [e.g. 011a43fe5b60424c](https://github.com/dtcxzyw/llvm-codegen-benchmark/blob/24627cd223f7ca9e686a898658cabba4d4339e7e/result/rvb23u64/011a43fe5b60424c.S)
> This is because of an opaque constant. What are opaque constants? I cannot find any documentation.
Opaque constants are constants that have been hoisted by the ConstantHoisting pass. https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
That pass uses the getIntImmCostInst TTI hook to decide what constants are expensive and can't be folded.
https://github.com/llvm/llvm-project/pull/157416
More information about the llvm-commits
mailing list