[all-commits] [llvm/llvm-project] 1e3957: [RISCV] CSE by swapping conditional branches (#71111)
Min-Yih Hsu via All-commits
all-commits at lists.llvm.org
Fri Nov 3 09:04:05 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 1e39575a981088e8596461a3511cce3ec4c3b274
https://github.com/llvm/llvm-project/commit/1e39575a981088e8596461a3511cce3ec4c3b274
Author: Min-Yih Hsu <min.hsu at sifive.com>
Date: 2023-11-03 (Fri, 03 Nov 2023)
Changed paths:
M llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
M llvm/lib/Target/RISCV/RISCVInstrInfo.h
A llvm/test/CodeGen/RISCV/branch-opt.ll
Log Message:
-----------
[RISCV] CSE by swapping conditional branches (#71111)
DAGCombiner, as well as InstCombine, tend to canonicalize GE/LE into
GT/LT, namely:
```
X >= C --> X > (C - 1)
```
Which sometime generates off-by-one constants that could have been CSE'd
with surrounding constants.
Instead of changing such canonicalization, this patch tries to swap
those branch conditions post-isel, in the hope of resurfacing more
constant CSE opportunities. More specifically, it performs the following
optimization:
For two constants C0 and C1 from
```
li Y, C0
li Z, C1
```
To remove redundnat `li Y, C0`,
1. if C1 = C0 + 1 we can turn:
(a) blt Y, X -> bge X, Z
(b) bge Y, X -> blt X, Z
2. if C1 = C0 - 1 we can turn:
(a) blt X, Y -> bge Z, X
(b) bge X, Y -> blt Z, X
This optimization will be done by PeepholeOptimizer through
RISCVInstrInfo::optimizeCondBranch.
More information about the All-commits
mailing list