[PATCH] D119373: [flang] Make folding of LEN less aggressive
Jean Perier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 01:23:51 PST 2022
jeanPerier added a comment.
> IsConstantExpr() is too strict of a test; IsScopeInvariantExpr() would be better.
@klausler, while I agree `IsConstantExpr` is throwing away valid rewrites, `IsScopeInvariantExpr` is still letting invalid rewrites like the following:
module m
contains
function cfoo(l)
integer :: l
character(l) :: cfoo
cfoo = "hello"
end function
subroutine bug(n)
integer :: n
print*, len(cfoo(n))
end subroutine
end module
`flang-new -fc1 -fdebug-unparse %` rewrites `print*, len(cfoo(n))` in `bug` into `PRINT *, int(cfoo%len,kind=4)`, that looks wrong to me. And if the `l` dummy argument is made `intent(in)` in `cfoo`, then `print*, len(cfoo(n))` is rewritten to `PRINT *, int(max(0_8,int(l,kind=8)),kind=4)`, which is also wrong. The information about the actual argument that defines the length was lost and cannot be retrieved anymore.
So a deeper analysis needs to be done here to avoid using `IsConstantExpr`, or LEN() should be changed.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119373/new/
https://reviews.llvm.org/D119373
More information about the llvm-commits
mailing list