Skip to content

Commit b1adf5d

Browse files
committed
Added negative tests and a comment.
1 parent 30e193f commit b1adf5d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,10 @@ class ReshapeAsElementalConversion
969969
"RESHAPE with ORDER argument");
970970

971971
// Verify that the element types of ARRAY, PAD and the result
972-
// match before doing any transformations.
972+
// match before doing any transformations. For example,
973+
// the character types of different lengths may appear in the dead
974+
// code, and it just does not make sense to inline hlfir.reshape
975+
// in this case (a runtime call might have less code size footprint).
973976
hlfir::Entity result = hlfir::Entity{reshape};
974977
hlfir::Entity array = hlfir::Entity{reshape.getArray()};
975978
mlir::Type elementType = array.getFortranElementType();

flang/test/HLFIR/simplify-hlfir-intrinsics-reshape.fir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,17 @@ func.func @reshape_char(%arg0: !fir.box<!fir.array<?x!fir.char<2,?>>>, %arg1: !f
212212
// CHECK: }
213213
// CHECK: return %[[VAL_10]] : !hlfir.expr<?x!fir.char<2,?>>
214214
// CHECK: }
215+
216+
func.func @reshape_negative_result_array_have_different_types(%arg0: !fir.box<!fir.array<?x!fir.char<2,1>>>, %arg1: !fir.ref<!fir.array<1xi32>>) -> !hlfir.expr<?x!fir.char<2,2>> {
217+
%res = hlfir.reshape %arg0 %arg1 : (!fir.box<!fir.array<?x!fir.char<2,1>>>, !fir.ref<!fir.array<1xi32>>) -> !hlfir.expr<?x!fir.char<2,2>>
218+
return %res : !hlfir.expr<?x!fir.char<2,2>>
219+
}
220+
// CHECK-LABEL: func.func @reshape_negative_result_array_have_different_types(
221+
// CHECK: hlfir.reshape %{{.*}} %{{.*}} : (!fir.box<!fir.array<?x!fir.char<2>>>, !fir.ref<!fir.array<1xi32>>) -> !hlfir.expr<?x!fir.char<2,2>>
222+
223+
func.func @reshape_negative_array_pad_have_different_types(%arg0: !fir.box<!fir.array<?x!fir.char<2,2>>>, %arg1: !fir.ref<!fir.array<1xi32>>, %arg2: !fir.box<!fir.array<?x!fir.char<2,1>>>) -> !hlfir.expr<?x!fir.char<2,2>> {
224+
%res = hlfir.reshape %arg0 %arg1 pad %arg2 : (!fir.box<!fir.array<?x!fir.char<2,2>>>, !fir.ref<!fir.array<1xi32>>, !fir.box<!fir.array<?x!fir.char<2,1>>>) -> !hlfir.expr<?x!fir.char<2,2>>
225+
return %res : !hlfir.expr<?x!fir.char<2,2>>
226+
}
227+
// CHECK-LABEL: func.func @reshape_negative_array_pad_have_different_types(
228+
// CHECK: hlfir.reshape %{{.*}} %{{.*}} pad %{{.*}} : (!fir.box<!fir.array<?x!fir.char<2,2>>>, !fir.ref<!fir.array<1xi32>>, !fir.box<!fir.array<?x!fir.char<2>>>) -> !hlfir.expr<?x!fir.char<2,2>>

0 commit comments

Comments
 (0)