[llvm] [X86] getConstVector - remove raw bits -> fp handling and leave it to getNode/FoldConstantArithmetic (PR #135337)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 11 02:14:09 PDT 2025


https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/135337

getConstVector could only handle f32/f64 vector element types from raw APInt bit data - instead of trying to add all supported fp types, just bitcast the integer equivalent and leave it getNode/FoldConstantArithmetic to perform the constant bitcast conversion

Tentative fix for a regression reported after #133913

>From 0a376e89169345201c6d44fd7378484baeabfed9 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Fri, 11 Apr 2025 10:11:38 +0100
Subject: [PATCH] [X86] getConstVector - remove raw bits -> fp handling and
 leave it to getNode/FoldConstantArithmetic

getConstVector could only handle f32/f64 vector element types from raw APInt bit data - instead of trying to add all supported fp types, just bitcast the integer equivalent and leave it getNode/FoldConstantArithmetic to perform the constant bitcast conversion

Tentative fix for a regression reported after #133913
---
 llvm/lib/Target/X86/X86ISelLowering.cpp | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 42ef817e01456..6e6431008e680 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -4014,6 +4014,7 @@ static SDValue getConstVector(ArrayRef<APInt> Bits, const APInt &Undefs,
   }
 
   MVT EltVT = ConstVecVT.getVectorElementType();
+  MVT EltIntVT = EltVT.changeTypeToInteger();
   for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
     if (Undefs[i]) {
       Ops.append(Split ? 2 : 1, DAG.getUNDEF(EltVT));
@@ -4024,14 +4025,8 @@ static SDValue getConstVector(ArrayRef<APInt> Bits, const APInt &Undefs,
     if (Split) {
       Ops.push_back(DAG.getConstant(V.extractBits(32, 0), dl, EltVT));
       Ops.push_back(DAG.getConstant(V.extractBits(32, 32), dl, EltVT));
-    } else if (EltVT == MVT::f32) {
-      APFloat FV(APFloat::IEEEsingle(), V);
-      Ops.push_back(DAG.getConstantFP(FV, dl, EltVT));
-    } else if (EltVT == MVT::f64) {
-      APFloat FV(APFloat::IEEEdouble(), V);
-      Ops.push_back(DAG.getConstantFP(FV, dl, EltVT));
     } else {
-      Ops.push_back(DAG.getConstant(V, dl, EltVT));
+      Ops.push_back(DAG.getBitcast(EltVT, DAG.getConstant(V, dl, EltIntVT)));
     }
   }
 



More information about the llvm-commits mailing list