Skip to content

[RISCV] Fix canFoldToVWWithSameExtension allowing different FP extensions #87978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

lukel97
Copy link
Contributor

@lukel97 lukel97 commented Apr 8, 2024

We previously weren't checking that the LHS was also FPExt, which means we might try to combine fadd x, (fpext y) to vfwadd.vv incorrectly during materialization.

However this never ends up happening because coincidentally, the VL and mask are always incompatible, since any non-extending operand doesn't set the VL or Mask. (I noticed this whilst working on a patch to relax the VL and Mask requirements)

So unfortunately I don't think there's a way to create test case for this currently since it's only a latent bug.

…ions

We previously weren't checking that the LHS was also FPExt, which means we might try to combine fadd x, (fpext y) to vfwadd.vv incorrectly during materialization.

However this never ends up happening because coincidentally, the VL and mask are always incompatible, since any non-extending operand doesn't set the VL or Mask. (I noticed this whilst working on a patch to relax the VL and Mask requirements)

So unfortunately I don't think there's a way to create test case for this currently since it's only a latent bug.
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2024

@llvm/pr-subscribers-backend-risc-v

Author: Luke Lau (lukel97)

Changes

We previously weren't checking that the LHS was also FPExt, which means we might try to combine fadd x, (fpext y) to vfwadd.vv incorrectly during materialization.

However this never ends up happening because coincidentally, the VL and mask are always incompatible, since any non-extending operand doesn't set the VL or Mask. (I noticed this whilst working on a patch to relax the VL and Mask requirements)

So unfortunately I don't think there's a way to create test case for this currently since it's only a latent bug.


Full diff: https://github.com/llvm/llvm-project/pull/87978.diff

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+1-1)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 279d8a435a04ca..b426f1a7b3791d 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -14090,7 +14090,7 @@ canFoldToVWWithSameExtensionImpl(SDNode *Root, const NodeExtensionHelper &LHS,
     return CombineResult(NodeExtensionHelper::getSExtOpcode(Root->getOpcode()),
                          Root, LHS, /*LHSExt=*/{ExtKind::SExt}, RHS,
                          /*RHSExt=*/{ExtKind::SExt});
-  if ((AllowExtMask & ExtKind::FPExt) && RHS.SupportsFPExt)
+  if ((AllowExtMask & ExtKind::FPExt) && LHS.SupportsFPExt && RHS.SupportsFPExt)
     return CombineResult(NodeExtensionHelper::getFPExtOpcode(Root->getOpcode()),
                          Root, LHS, /*LHSExt=*/{ExtKind::FPExt}, RHS,
                          /*RHSExt=*/{ExtKind::FPExt});

Copy link
Contributor

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@sun-jacobi sun-jacobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out this! LGTM

@lukel97 lukel97 merged commit 8b3b4a9 into llvm:main Apr 8, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants