[flang-commits] [flang] [Flang] Allow Intrinsic simpification with min/maxloc dim and scalar result (PR #81619)
David Green via flang-commits
flang-commits at lists.llvm.org
Thu Feb 15 02:20:20 PST 2024
davemgreen wrote:
> > OK thanks for checking - Maybe this cannot get away with converting the array to an int. Let me put up a new version where it changes the alloc type and if there are still problems we can try and figure out why.
>
> I've looked at the test results. There were two problems. First, one of our tests started issuing warnings at compile time when lowering. Here's an example that shows the problem:
>
> ```
> program bug
> real :: x(2) = [ 1.0, 2.0 ]
> call test(x,-1)
> contains
> subroutine test(array, dim)
> real,intent(in) :: array(2)
> integer,intent(in) :: dim
> integer :: loc
> loc = minloc(array,dim)
> end subroutine
> end program
> ```
>
> Second,I'm seeing differences in what floating point exceptions get raised when doing IEEE arithmetic. Here's a program that shows that difference:
>
> ```
> program bug
> real :: a(3), nan, positive_infinity
>
> nan = 0.0
> positive_infinity = 0.0
> nan = 0.0/nan
> positive_infinity = 1.0/positive_infinity
>
> a(3) = positive_infinity
> a(1:2) = nan
> if (minloc (a, dim = 1).ne.3) STOP 5
> end
> ```
Oh, thanks for the details. That certainly isn't what I expected the problems to be!
I had looked into the Nan issue a little last week, but did not think to test it with inf. This will be a pre-existing issue that is now starting to happen with dim too, as in a test like the one below. I'll see about getting that fixed.
```
program bug
real :: a(3), nan, positive_infinity
integer :: b(1)
nan = 0.0
positive_infinity = 0.0
nan = 0.0/nan
positive_infinity = 1.0/positive_infinity
a(3) = positive_infinity
a(1:2) = nan
b = minloc (a)
if (b(1) .ne.3) STOP 5
end
```
For the other issue - I can imagine that a previous runtime error now becomes a compile time warning. I don't see the same warning, but it seems to go from a runtime error to just working (there is only really one valid value for dim as far as I understand) and it appears gfortran does the same. I can maybe make it only work for constant dim values, if that would be better than not producing a runtime error message?
https://github.com/llvm/llvm-project/pull/81619
More information about the flang-commits
mailing list