[llvm] [RISCV] Fix canFoldToVWWithSameExtension allowing different FP extensions (PR #87978)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 8 03:10:35 PDT 2024


https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/87978

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.


>From 3ada660beb5924efaa40d51cf5f2389764b1ab88 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Mon, 8 Apr 2024 18:02:30 +0800
Subject: [PATCH] [RISCV] Fix canFoldToVWWithSameExtension allowing different
 FP extensions

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.
---
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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});



More information about the llvm-commits mailing list