[flang-commits] [flang] [flang][CodeGen] Add `fir::ShiftType` to LLVM type conversion (PR #213675)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Mon Aug 3 06:44:32 PDT 2026


https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/213675

Mirrors the existing ShapeType / ShapeShiftType converters: a `!fir.shift<N>` becomes `!llvm.struct<(i64 x N)>`.

Co-Authored-By: Claude

>From 1e700d38e915b01ddda9ccba9e069cb4291dc048 Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at gmail.com>
Date: Mon, 3 Aug 2026 01:30:03 -0700
Subject: [PATCH] [flang][CodeGen] Add `fir::ShiftType` to LLVM type conversion

Mirrors the existing ShapeType / ShapeShiftType converters: a
`!fir.shift<N>` becomes `!llvm.struct<(i64 x N)>`.

Co-Authored-By: Claude
---
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  6 ++++++
 flang/test/Fir/convert-to-llvm.fir            | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
index 291cd8e1796a7..31194f9c274f3 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
@@ -135,6 +135,12 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
     return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members,
                                                   /*isPacked=*/false);
   });
+  addConversion([&](fir::ShiftType shift) {
+    mlir::Type i64Ty = mlir::IntegerType::get(&getContext(), 64);
+    llvm::SmallVector<mlir::Type> members(shift.getRank(), i64Ty);
+    return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members,
+                                                  /*isPacked=*/false);
+  });
   addConversion([&](fir::TypeDescType tdesc) {
     return convertTypeDescType(tdesc.getContext());
   });
diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir
index 6af50b963130e..fe803ea2e65af 100644
--- a/flang/test/Fir/convert-to-llvm.fir
+++ b/flang/test/Fir/convert-to-llvm.fir
@@ -1391,6 +1391,22 @@ func.func @dead_shift() {
 // CHECK: %{{.*}} = llvm.mlir.constant(0 : index) : i{{.*}}
 // CHECK-NEXT: llvm.return
 
+// -----
+
+// Test that !fir.shift<N> flowing through the IR as a value (here, a
+// function argument) has a working type conversion to a struct of i64s,
+// matching !fir.shape<N> / !fir.shape_shift<N>.
+
+func.func @shift_value(%s: !fir.shift<1>) -> !fir.shift<1> {
+  return %s : !fir.shift<1>
+}
+
+// CHECK-LABEL: llvm.func @shift_value
+// CHECK-SAME:  (%[[ARG:.*]]: !llvm.struct<(i64)>) -> !llvm.struct<(i64)>
+// CHECK:       llvm.return %[[ARG]] : !llvm.struct<(i64)>
+
+// -----
+
 func.func @dead_shape() {
   %c0 = arith.constant 0 : index
   %0 = fir.shape %c0 : (index) -> !fir.shape<1>



More information about the flang-commits mailing list