[PATCH] D104612: [CGP][RISCV] Teach CodeGenPrepare::optimizeSwitchInst to honor isSExtCheaperThanZExt.
Jessica Clarke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 23 11:43:34 PDT 2021
jrtc27 added inline comments.
================
Comment at: llvm/lib/CodeGen/CodeGenPrepare.cpp:7014-7016
+ // Some targets prefer SExt over ZExt, honor that.
+ if (TLI->isSExtCheaperThanZExt(OldVT, RegType))
+ ExtType = Instruction::SExt;
----------------
jrtc27 wrote:
> Do we not want to avoid this in the case this is a function argument that is already being zero-extended? i.e. something like:
>
> ```
> Instruction::CastOps ExtType = Instruction::CastOpsEnd;
> if (auto *Arg = dyn_cast<Argument>(Cond)) {
> if (Arg->hasSExtAttr())
> ExtType = Instruction::SExt;
> else if (Arg->hasZExtAttr())
> ExtType = Instruction::ZExt;
> }
> if (ExtType == Instruction::CastOpsEnd) {
> if (TLI->isSExtCheaperThanZExt(OldVT, RegType))
> ExtType = Instruction::SExt;
> else
> ExtType = Instruction::ZExt;
> }
> ```
> (slightly abusing CastOpsEnd as being one past the last valid op, and thus a sentinel, though you could write it in other ways too if you wanted)
>
Or maybe the fact that sext is cheaper means the saving for each case's extending to match outweighs the cost of having to also extend the argument?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104612/new/
https://reviews.llvm.org/D104612
More information about the llvm-commits
mailing list