[flang-commits] [flang] c024fa4 - [flang] Use llvm.zext when converting from i1 -> iXX
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Mon Mar 13 22:31:55 PDT 2023
Author: Valentin Clement
Date: 2023-03-14T06:31:49+01:00
New Revision: c024fa4b5bd6cff4bd5521bfd94fbbb9586a78ee
URL: https://github.com/llvm/llvm-project/commit/c024fa4b5bd6cff4bd5521bfd94fbbb9586a78ee
DIFF: https://github.com/llvm/llvm-project/commit/c024fa4b5bd6cff4bd5521bfd94fbbb9586a78ee.diff
LOG: [flang] Use llvm.zext when converting from i1 -> iXX
CodeGen used llvm.sext when converting fir.convert %0 : (i1) -> iXX
where iXX is any integer. This leads to wrong values when the initial
i1 is equal to 1.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D145984
Added:
Modified:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/test/Fir/convert-to-llvm.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 51df08bffad33..6b4591789c545 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -937,6 +937,10 @@ struct ConvertOpConversion : public FIROpConversion<fir::ConvertOp> {
rewriter.replaceOpWithNewOp<mlir::LLVM::TruncOp>(convert, toTy, op0);
return mlir::success();
}
+ if (fromFirTy == i1Type) {
+ rewriter.replaceOpWithNewOp<mlir::LLVM::ZExtOp>(convert, toTy, op0);
+ return mlir::success();
+ }
rewriter.replaceOpWithNewOp<mlir::LLVM::SExtOp>(convert, toTy, op0);
return mlir::success();
}
diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir
index 85b8f666a18f8..cbfb2283ccbc6 100644
--- a/flang/test/Fir/convert-to-llvm.fir
+++ b/flang/test/Fir/convert-to-llvm.fir
@@ -739,6 +739,16 @@ func.func @convert_from_int(%arg0 : i32) {
// CHECK: %{{.*}} = llvm.sext %[[ARG0]] : i32 to i64
// CHECK: %{{.*}} = llvm.inttoptr %{{.*}} : i64 to !llvm.ptr<i64>
+
+func.func @convert_from_i1(%arg0 : i1) {
+ %0 = fir.convert %arg0 : (i1) -> i32
+ return
+}
+
+// CHECK-LABEL: convert_from_i1(
+// CHECK-SAME: %[[ARG0:.*]]: i1
+// CHECK: %{{.*}} = llvm.zext %[[ARG0]] : i1 to i32
+
// -----
// Test `fir.convert` operation conversion from !fir.ref<> type.
More information about the flang-commits
mailing list