Skip to content

Commit 8e65ce5

Browse files
committed
[flang2] Generate loads of complex variables with correct alignment
flang2 calls the function make_load() to create various types of load instructions in the LLVM IR output. The function accepts a "flags" argument of type LL_InstrListFlags which should encode the alignment of the load, among other things. Apparently, for the IL_LDSCMPLX, IL_LDDCMPLX, and IL_LDQCMPLX opcodes, the flags had never been computed correctly. This patch makes such loads consistent with loads of other types, and also adds a test case.
1 parent 3de1cba commit 8e65ce5

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
! See https://llvm.org/LICENSE.txt for license information.
3+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
! Check that load instructions are emitted with correct alignment.
6+
7+
! RUN: %flang -S -emit-flang-llvm %s -o %t.ll
8+
! RUN: FileCheck %s < %t.ll
9+
10+
! CHECK: load i8, ptr %in1, align 1
11+
function bpass(in1)
12+
logical(kind=1) :: in1, bpass
13+
bpass = in1
14+
end function bpass
15+
16+
! CHECK: load i32, ptr %in1, align 4
17+
function ipass(in1)
18+
integer(kind=4) :: in1, ipass
19+
ipass = in1
20+
end function ipass
21+
22+
! CHECK: load i64, ptr %in1, align 8
23+
function lpass(in1)
24+
integer(kind=8) :: in1, lpass
25+
lpass = in1
26+
end function lpass
27+
28+
! CHECK: load float, ptr %in1, align 4
29+
function fpass(in1)
30+
real(kind=4) :: in1, fpass
31+
fpass = in1
32+
end function fpass
33+
34+
! CHECK: load double, ptr %in1, align 8
35+
function dpass(in1)
36+
real(kind=8) :: in1, dpass
37+
dpass = in1
38+
end function dpass
39+
40+
! CHECK: load <{float, float}>, ptr %in1, align 8
41+
function cfpass(in1)
42+
complex(kind=4) :: in1, cfpass
43+
cfpass = in1
44+
end function cfpass
45+
46+
! CHECK: load <{double, double}>, ptr %in1, align 16
47+
function cdpass(in1)
48+
complex(kind=8) :: in1, cdpass
49+
cdpass = in1
50+
end function cdpass

tools/flang2/flang2exe/cgmain.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8572,15 +8572,12 @@ gen_llvm_expr(int ilix, LL_Type *expected_type)
85728572
ld_ili = ILI_OPND(ilix, 1);
85738573
nme_ili = ILI_OPND(ilix, 2);
85748574
msz = (MSZ)ILI_OPND(ilix, 3);
8575-
flags = opc == IL_LDSCMPLX ? DT_CMPLX
8576-
#ifdef TARGET_SUPPORTS_QUADFP
8577-
: opc == IL_LDQCMPLX ? DT_QCMPLX
8578-
#endif
8579-
: DT_DCMPLX;
85808575
operand = gen_address_operand(ld_ili, nme_ili, false,
85818576
make_ptr_lltype(expected_type), (MSZ)-1);
85828577
assert(operand->ll_type->data_type == LL_PTR,
85838578
"Invalid operand for cmplx load", ilix, ERR_Fatal);
8579+
flags =
8580+
ldst_instr_flags_from_dtype_nme(msz_dtype(msz), nme_ili);
85848581
operand =
85858582
make_load(ilix, operand, operand->ll_type->sub_types[0], msz, flags);
85868583
} break;

0 commit comments

Comments
 (0)