Skip to content

Commit c5c8ae4

Browse files
[flang] Use i16 instead of i2 for cmdstat (llvm#91647)
The code for preparing cmdstat was generating an i2 constant with value 0, casting it, and then storing it into i16 storage. Just generate i16 constant directly.
1 parent 9232591 commit c5c8ae4

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6306,11 +6306,9 @@ void IntrinsicLibrary::genSystem(llvm::ArrayRef<fir::ExtendedValue> args) {
63066306
// Create a dummmy cmdstat to prevent EXECUTE_COMMAND_LINE terminate itself
63076307
// when cmdstat is assigned with a non-zero value but not present
63086308
mlir::Value tempValue =
6309-
builder.createIntegerConstant(loc, builder.getI2Type(), 0);
6309+
builder.createIntegerConstant(loc, builder.getI16Type(), 0);
63106310
mlir::Value temp = builder.createTemporary(loc, builder.getI16Type());
6311-
mlir::Value castVal =
6312-
builder.createConvert(loc, builder.getI16Type(), tempValue);
6313-
builder.create<fir::StoreOp>(loc, castVal, temp);
6311+
builder.create<fir::StoreOp>(loc, tempValue, temp);
63146312
mlir::Value cmdstatBox = builder.createBox(loc, temp);
63156313

63166314
mlir::Value cmdmsgBox =

flang/test/Lower/Intrinsics/system-optional.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ subroutine all_args(command, exitstat)
1919
! CHECK-NEXT: %[[absentIntBox:.*]] = fir.absent !fir.box<i32>
2020
! CHECK-NEXT: %[[exitstatRealBox:.*]] = arith.select %[[exitstatIsPresent]], %[[exitstatBox]], %[[absentIntBox]] : !fir.box<i32>
2121
! CHECK-NEXT: %[[true:.*]] = arith.constant true
22-
! CHECK-NEXT: %[[c0_i2:.*]] = arith.constant 0 : i2
23-
! CHECK-NEXT: %[[c0_i16:.*]] = fir.convert %[[c0_i2]] : (i2) -> i16
22+
! CHECK-NEXT: %[[c0_i16:.*]] = arith.constant 0 : i16
2423
! CHECK-NEXT: fir.store %[[c0_i16]] to %[[cmdstatVal]] : !fir.ref<i16>
2524
! CHECK-NEXT: %[[cmdstatBox:.*]] = fir.embox %[[cmdstatVal]] : (!fir.ref<i16>) -> !fir.box<i16>
2625
! CHECK-NEXT: %[[absentBox:.*]] = fir.absent !fir.box<none>

flang/test/Lower/Intrinsics/system.f90

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ subroutine all_args(command, exitstat)
1515
! CHECK-NEXT: %[[commandBox:.*]] = fir.embox %[[commandDeclare]]#1 typeparams %[[commandUnbox]]#1 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.box<!fir.char<1,?>>
1616
! CHECK-NEXT: %[[exitstatBox:.*]] = fir.embox %[[exitstatDeclare]]#1 : (!fir.ref<i32>) -> !fir.box<i32>
1717
! CHECK-NEXT: %[[true:.*]] = arith.constant true
18-
! CHECK-NEXT: %[[c0_i2:.*]] = arith.constant 0 : i2
19-
! CHECK-NEXT: %[[c0_i16:.*]] = fir.convert %[[c0_i2]] : (i2) -> i16
18+
! CHECK-NEXT: %[[c0_i16:.*]] = arith.constant 0 : i16
2019
! CHECK-NEXT: fir.store %[[c0_i16]] to %[[cmdstatVal]] : !fir.ref<i16>
2120
! CHECK-NEXT: %[[cmdstatBox:.*]] = fir.embox %[[cmdstatVal]] : (!fir.ref<i16>) -> !fir.box<i16>
2221
! CHECK-NEXT: %[[absentBox:.*]] = fir.absent !fir.box<none>
@@ -41,8 +40,7 @@ subroutine only_command(command)
4140
! CHECK-NEXT: %[[commandBox:.*]] = fir.embox %[[commandDeclare]]#1 typeparams %[[commandUnbox]]#1 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.box<!fir.char<1,?>>
4241
! CHECK-NEXT: %[[true:.*]] = arith.constant true
4342
! CHECK-NEXT: %[[absentBox:.*]] = fir.absent !fir.box<none>
44-
! CHECK-NEXT: %[[c0_i2:.*]] = arith.constant 0 : i2
45-
! CHECK-NEXT: %[[c0_i16:.*]] = fir.convert %[[c0_i2]] : (i2) -> i16
43+
! CHECK-NEXT: %[[c0_i16:.*]] = arith.constant 0 : i16
4644
! CHECK-NEXT: fir.store %[[c0_i16]] to %[[cmdstatVal]] : !fir.ref<i16>
4745
! CHECK-NEXT: %[[cmdstatBox:.*]] = fir.embox %[[cmdstatVal]] : (!fir.ref<i16>) -> !fir.box<i16>
4846
! CHECK-NEXT: %[[absentBox2:.*]] = fir.absent !fir.box<none>

0 commit comments

Comments
 (0)