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

via flang-commits flang-commits at lists.llvm.org
Fri Aug 7 03:19:58 PDT 2026


Author: Kareem Ergawy
Date: 2026-08-07T12:19:53+02:00
New Revision: 56b14c53303f28d887de0e308355c81eef8df6bd

URL: https://github.com/llvm/llvm-project/commit/56b14c53303f28d887de0e308355c81eef8df6bd
DIFF: https://github.com/llvm/llvm-project/commit/56b14c53303f28d887de0e308355c81eef8df6bd.diff

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

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

Co-Authored-By: Claude

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/TypeConverter.cpp
    flang/test/Fir/convert-to-llvm.fir

Removed: 
    


################################################################################
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