Skip to content

Commit 87f56d6

Browse files
committed
Improve the expansion of MINLOC/MAXLOC
Handle maxloc/maxval/minloc/minval expansion if the expression being tested is not a simple variable by using a temp.
1 parent aeedd9a commit 87f56d6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/flang1/flang1exe/func.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6235,6 +6235,19 @@ inline_reduction_f90(int ast, int dest, int lc, LOGICAL *doremove)
62356235
astsubscrtmp = dest;
62366236
} else
62376237
astsubscrtmp = asttmp;
6238+
if (A_OPTYPEG(ast) == I_MAXLOC || A_OPTYPEG(ast) == I_MINLOC ||
6239+
A_OPTYPEG(ast) == I_MAXVAL || A_OPTYPEG(ast) == I_MINVAL) {
6240+
/* if the expression being reduced is nontrivial, assign to a temp */
6241+
if (A_TYPEG(ast2) == A_SUBSCR || A_TYPEG(ast2) == A_ID) {
6242+
} else {
6243+
/* create a temporary scalar */
6244+
int temprhs = sym_get_scalar(SYMNAME(sptr), "l", dtyperes);
6245+
/* assign the RHS to temprhs */
6246+
int std = mk_assn_stmt(mk_id(temprhs), ast2, dtyperes);
6247+
add_stmt_before(std, stdnext);
6248+
ast2 = mk_id(temprhs);
6249+
}
6250+
}
62386251
}
62396252
dtsclr = DDTG(dtypetmp);
62406253
switch (A_OPTYPEG(ast)) {

0 commit comments

Comments
 (0)