If a phi has a constant operand it will need to be materialized at some
point, so account for this cost by reusing the logic used for store
immediates.
This should eventually be improved to also handle scalar constants.
Details
- Reviewers
ABataev RKSimon craig.topper reames
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll | ||
---|---|---|
9 | The generated code: f: # @f .cfi_startproc # %bb.0: vsetivli zero, 2, e8, mf8, ta, ma vid.v v8 andi a0, a0, 1 vadd.vv v8, v8, v8 beqz a0, .LBB0_2 # %bb.1: vrsub.vi v8, v8, 1 ret .LBB0_2: # %b vadd.vi v8, v8, -1 ret |
llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll | ||
---|---|---|
9 | I have one concern here about loops. In the loop we need to account for the materialization cost only once, if the input constant is a live-in. So for such values better to consider it free, I assume. |
llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll | ||
---|---|---|
9 | That's a good point. The cost of constants in stores must also be currently affected by this too right? |
llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll | ||
---|---|---|
9 | Looks so. But it requires some significant rework of the cost model, I assume. For phi's you can try just to check if there is a loop in the graph (with the small enough limit), without actual analysis/use of the Loop objects. |
llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll | ||
---|---|---|
9 | Yes, and it it looks like arithmetic instructions are also affected, not just on RISC-V but on at least AArch64 too. |
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | ||
---|---|---|
1428 | const OperandValueInfo &OpInfo |
After discussing offline with @reames, we're not sure if this is the most accurate way to model constant costs in phi nodes. Moving it off the review queue for the meantime
const OperandValueInfo &OpInfo