[Mlir-commits] [mlir] [MLIR][MLIRToLLVM] Fix zero fp value to array translation (PR #160713)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 25 07:29:52 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
Author: Alexey Bataev (alexey-bataev)
<details>
<summary>Changes</summary>
The translator should not generate zeroinitilizer on fp all zero values,
since it may affect signedness of zeroes
Fixes #<!-- -->160437
---
Full diff: https://github.com/llvm/llvm-project/pull/160713.diff
2 Files Affected:
- (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+1-1)
- (added) mlir/test/Target/LLVMIR/global_float_array.mlir (+4)
``````````diff
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index adc5a74e2031f..5a3eb209f0a92 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -647,7 +647,7 @@ llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
llvm::ElementCount::get(numElements, /*Scalable=*/isScalable), child);
if (llvmType->isArrayTy()) {
auto *arrayType = llvm::ArrayType::get(elementType, numElements);
- if (child->isZeroValue()) {
+ if (child->isZeroValue() && !elementType->isFPOrFPVectorTy()) {
return llvm::ConstantAggregateZero::get(arrayType);
} else {
if (llvm::ConstantDataSequential::isElementTypeCompatible(
diff --git a/mlir/test/Target/LLVMIR/global_float_array.mlir b/mlir/test/Target/LLVMIR/global_float_array.mlir
new file mode 100644
index 0000000000000..eba7948d2c55e
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/global_float_array.mlir
@@ -0,0 +1,4 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// CHECK: @test = internal global [1 x float] [float -0.000000e+00]
+llvm.mlir.global internal @test(dense<-0.000000e+00> : tensor<1xf32>) {addr_space = 0 : i32} : !llvm.array<1 x f32>
``````````
</details>
https://github.com/llvm/llvm-project/pull/160713
More information about the Mlir-commits
mailing list