This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support select/merge like ops for fp16 vectors when only have Zvfhmin
ClosedPublic

Authored by jacquesguan on Aug 28 2023, 8:07 PM.

Details

Summary

This patch supports VP_MERGE, VP_SELECT, SELECT, SELECT_CC for fp16 vectors when only have Zvfhmin.

Diff Detail

Event Timeline

jacquesguan created this revision.Aug 28 2023, 8:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2023, 8:07 PM
jacquesguan requested review of this revision.Aug 28 2023, 8:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2023, 8:07 PM
craig.topper added inline comments.Aug 28 2023, 8:11 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14485

I'm not sure what "failed promotion" means

rewrite the comment.

jacquesguan marked an inline comment as done.Aug 28 2023, 8:26 PM
jacquesguan added inline comments.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14485

I rewrite this comment, it should be a bit more clear.

craig.topper added inline comments.Aug 28 2023, 8:28 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14486

What prevents this for constants that aren't 0?

jacquesguan marked an inline comment as done.

pre lower all constant splat

jacquesguan marked an inline comment as done.

Skip constant in promotion.

craig.topper added inline comments.Aug 29 2023, 3:21 PM
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
5509 ↗(On Diff #554211)

This seems like it might be a RISC-V specific issue and not something we should do in target specific code.

What code is reversing the promotion? That code should be checking isOperationLegal

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
5509 ↗(On Diff #554211)

If you end up doing this check, either here on in RISCV specific code, you can simplify to if (isa<ConstantSDNode>(Scalar))

Move back to riscv target

jacquesguan added inline comments.Sep 6 2023, 2:32 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
5509 ↗(On Diff #554211)

Thanks for your advice, I use implement it in RISCV target specific logic now.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14485

How does this approach compare to making the constant folder of getNode not do the fold when only have zvfhmin?

jacquesguan added inline comments.Sep 14 2023, 6:54 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14485

I have no idea about how to make the constant folder of getNode not do the fold when only have zvfhmin if we just want to change the RISCV target specific code. Do you have some advice?

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14485

Here is one idea (using pseudo code):

Target::isConstantFoldLegal(InformationAboutFold) { return true; }
RISCVTarget::isConstantFoldLegal(InformationAboutFold I) override {
  if (isConstantFoldFromF32ToF16(I) && onlyHaveZvfhmin())
    return false;
  return true;
}

ConstantFolder::fold(MachineInstr NotFoldedYet, InformationAboutFold I) {
  if (Target.isConstantFoldLegal(I))
    return NotFoldedYet;
  return doFold(NotFoldedYet);
}

The comment in the code points out that the current solution is a work around to avoid a problem that would have been introduced by the constant folder. If we solve it in the constant folder then we avoid needing to do a work around and allow the lowering to happen at the normal time.

That being said, I'm not confident that there is anything wrong with lowering early since I am not an expert in this area. I wonder if you have any thoughts (or @craig.topper when he is back from vacation).

craig.topper added inline comments.Sep 15 2023, 1:31 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14485

I think I'd rather see this implemented as a custom lowering of SPLAT_VECTOR rather than a combine. That likely means we need to manually implement the promotion of SPLAT_VECTOR for the non-constant case in the same lowering since we can't use Promote for setOperationAction, but that doesn't seem like a blocker.

change to custom lowering

jacquesguan marked an inline comment as done.Sep 19 2023, 1:01 AM
jacquesguan added inline comments.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
14485

Done, I switched to the custom lowering.

craig.topper added inline comments.Sep 19 2023, 10:14 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6014

The break; is unreachable due to the return above it.

jacquesguan marked an inline comment as done.

remove unreachable break

jacquesguan marked an inline comment as done.Sep 19 2023, 11:48 PM
jacquesguan added inline comments.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6014

Fixed.

rebase and fix test

This revision is now accepted and ready to land.Sep 26 2023, 2:59 PM

rebase main