Bug 106017 - [PowerPC] No array-to-pointer conversion for MMA accumulator
Summary: [PowerPC] No array-to-pointer conversion for MMA accumulator
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Peter Bergner
URL: https://gcc.gnu.org/pipermail/gcc-pat...
Keywords:
: 106015 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-06-17 14:34 UTC by Nemanja Ivanovic
Modified: 2022-08-30 01:14 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc
Build:
Known to work:
Known to fail: 10.0, 11.0, 12.0, 13.0
Last reconfirmed: 2022-06-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nemanja Ivanovic 2022-06-17 14:34:46 UTC
It appears that the typical array to pointer conversion for function arguments does not work for MMA accumulator types. The user has to explicitly convert.

Code:
$ cat aa.c 
void takeacc(__vector_quad *);
void passacc() {
        __vector_quad arr[4];
#ifdef _EXPLICIT
        takeacc(&arr[0]);
#else
        takeacc(arr);
#endif
}

Compile (success):
$ gcc -mcpu=power10 -O3 aa.c -S -D_EXPLICIT && echo Success
Success

Compile (failure):
$ gcc -mcpu=power10 -O3 aa.c -S && echo Success
aa.c: In function 'passacc':
aa.c:7:9: error: invalid conversion to type '* __vector_quad'
    7 |         takeacc(arr);
      |         ^~~~~~~

Version:
$ gcc --version
gcc (GCC) 12.1.1 20220524 [releases/gcc-12 r12-8410-gf0a0aeec44]
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Segher Boessenkool 2022-06-17 17:16:13 UTC
Confirmed.

C allows to convert a pointer to data to any other pointer to data (possibly
modulo alignment restrictions).  What is *not* valid is accessing anything via
a type not compatible with its effective type (or via a character type).

So the restriction in rs6000_invalid_conversion errors for valid C programs.
What was it intended to accomplish?
Comment 2 Peter Bergner 2022-06-17 17:31:43 UTC
(In reply to Segher Boessenkool from comment #1)
> So the restriction in rs6000_invalid_conversion errors for valid C programs.
> What was it intended to accomplish?

We do not want or allow automatic conversions between the opaque __vector_pair and __vector_quad types and other types and those are correctly disallowed there.  Conversions between those types needs to go through the builtins defined for that.

As for the pointer conversions tested there, I guess they came along for the ride?  Nemanja, do you remember the history there?  Or does LLVM allow the pointer conversions and it's just GCC that complains?
Comment 3 Segher Boessenkool 2022-06-17 17:35:29 UTC
(In reply to Peter Bergner from comment #2)
> We do not want or allow automatic conversions between the opaque
> __vector_pair and __vector_quad types and other types and those are
> correctly disallowed there.

Of course, but that is not what this is about...

> As for the pointer conversions tested there, I guess they came along for the
> ride?  Nemanja, do you remember the history there?  Or does LLVM allow the
> pointer conversions and it's just GCC that complains?

... this is.

Possibly the restriction prevents some ICEs elsewhere, but those just need to
be solved then, not hidden.
Comment 4 Nemanja Ivanovic 2022-06-17 19:19:00 UTC
(In reply to Peter Bergner from comment #2)
> (In reply to Segher Boessenkool from comment #1)
> > So the restriction in rs6000_invalid_conversion errors for valid C programs.
> > What was it intended to accomplish?
> 
> We do not want or allow automatic conversions between the opaque
> __vector_pair and __vector_quad types and other types and those are
> correctly disallowed there.  Conversions between those types needs to go
> through the builtins defined for that.
> 
> As for the pointer conversions tested there, I guess they came along for the
> ride?  Nemanja, do you remember the history there?  Or does LLVM allow the
> pointer conversions and it's just GCC that complains?

Yes, the desired semantics are to disallow implicit or explicit conversions from these types to any other types. But pointer casts (presumably including reinterpret_cast in C++) should be fair game. Clang allows these conversions.
Comment 5 Segher Boessenkool 2022-06-17 19:51:41 UTC
Okay, I'll handle it.
Comment 6 Segher Boessenkool 2022-06-17 20:50:17 UTC
FWIW, reinterpret_cast allows exactly the same things as C casts (but with the
obvious C++ extensions: member objects, member functions, C++'s concept of
lvalue, that kins of thing).  It is not similar to bit_cast at all.
Comment 7 Peter Bergner 2022-08-27 17:28:59 UTC
I think we just want to remove the entire section in rs6000_invalid_conversion() that checks the XOmode/OOmode pointer conversions.  Doing that fixes the ICE and fixes the PR106015 ICE too.  I'm doing a bootstrap and regtest of that patch now.
Comment 8 Peter Bergner 2022-08-27 17:30:07 UTC
*** Bug 106015 has been marked as a duplicate of this bug. ***
Comment 9 Peter Bergner 2022-08-27 18:27:25 UTC
(In reply to Peter Bergner from comment #7)
> I think we just want to remove the entire section in
> rs6000_invalid_conversion() that checks the XOmode/OOmode pointer
> conversions.  Doing that fixes the ICE and fixes the PR106015 ICE too.  I'm
> doing a bootstrap and regtest of that patch now.

Testing was clean, so I'll submit the patch.
Comment 10 GCC Commits 2022-08-28 00:44:57 UTC
The master branch has been updated by Peter Bergner <bergner@gcc.gnu.org>:

https://gcc.gnu.org/g:1ae1325f24cea1698b56e4299d95446a1f7b90a2

commit r13-2239-g1ae1325f24cea1698b56e4299d95446a1f7b90a2
Author: Peter Bergner <bergner@linux.ibm.com>
Date:   Sat Aug 27 19:44:16 2022 -0500

    rs6000: Allow conversions of MMA pointer types [PR106017]
    
    GCC incorrectly disables conversions between MMA pointer types, which
    are allowed with clang.  The original intent was to disable conversions
    between MMA types and other other types, but pointer conversions should
    have been allowed.  The fix is to just remove the MMA pointer conversion
    handling code altogether.
    
    gcc/
            PR target/106017
            * config/rs6000/rs6000.cc (rs6000_invalid_conversion): Remove handling
            of MMA pointer conversions.
    
    gcc/testsuite/
            PR target/106017
            * gcc.target/powerpc/pr106017.c: New test.
Comment 11 GCC Commits 2022-08-29 22:38:31 UTC
The releases/gcc-12 branch has been updated by Peter Bergner <bergner@gcc.gnu.org>:

https://gcc.gnu.org/g:22ff125247ff5328ad4544aef939d491618d714d

commit r12-8726-g22ff125247ff5328ad4544aef939d491618d714d
Author: Peter Bergner <bergner@linux.ibm.com>
Date:   Sat Aug 27 19:44:16 2022 -0500

    rs6000: Allow conversions of MMA pointer types [PR106017]
    
    GCC incorrectly disables conversions between MMA pointer types, which
    are allowed with clang.  The original intent was to disable conversions
    between MMA types and other other types, but pointer conversions should
    have been allowed.  The fix is to just remove the MMA pointer conversion
    handling code altogether.
    
    gcc/
            PR target/106017
            * config/rs6000/rs6000.cc (rs6000_invalid_conversion): Remove handling
            of MMA pointer conversions.
    
    gcc/testsuite/
            PR target/106017
            * gcc.target/powerpc/pr106017.c: New test.
    
    (cherry picked from commit 1ae1325f24cea1698b56e4299d95446a1f7b90a2)
Comment 12 GCC Commits 2022-08-30 00:22:02 UTC
The releases/gcc-11 branch has been updated by Peter Bergner <bergner@gcc.gnu.org>:

https://gcc.gnu.org/g:f494a85f0bf653c3128b376c1abf821a27748c11

commit r11-10227-gf494a85f0bf653c3128b376c1abf821a27748c11
Author: Peter Bergner <bergner@linux.ibm.com>
Date:   Sat Aug 27 19:44:16 2022 -0500

    rs6000: Allow conversions of MMA pointer types [PR106017]
    
    GCC incorrectly disables conversions between MMA pointer types, which
    are allowed with clang.  The original intent was to disable conversions
    between MMA types and other other types, but pointer conversions should
    have been allowed.  The fix is to just remove the MMA pointer conversion
    handling code altogether.
    
    gcc/
            PR target/106017
            * config/rs6000/rs6000.c (rs6000_invalid_conversion): Remove handling
            of MMA pointer conversions.
    
    gcc/testsuite/
            PR target/106017
            * gcc.target/powerpc/pr106017.c: New test.
    
    (cherry picked from commit 1ae1325f24cea1698b56e4299d95446a1f7b90a2)
Comment 13 GCC Commits 2022-08-30 01:13:06 UTC
The releases/gcc-10 branch has been updated by Peter Bergner <bergner@gcc.gnu.org>:

https://gcc.gnu.org/g:3927bd9f9150576f2905c8930732c419f1850fca

commit r10-10966-g3927bd9f9150576f2905c8930732c419f1850fca
Author: Peter Bergner <bergner@linux.ibm.com>
Date:   Sat Aug 27 19:44:16 2022 -0500

    rs6000: Allow conversions of MMA pointer types [PR106017]
    
    GCC incorrectly disables conversions between MMA pointer types, which
    are allowed with clang.  The original intent was to disable conversions
    between MMA types and other other types, but pointer conversions should
    have been allowed.  The fix is to just remove the MMA pointer conversion
    handling code altogether.
    
    gcc/
            PR target/106017
            * config/rs6000/rs6000.c (rs6000_invalid_conversion): Remove handling
            of MMA pointer conversions.
    
    gcc/testsuite/
            PR target/106017
            * gcc.target/powerpc/pr106017.c: New test.
    
    (cherry picked from commit 1ae1325f24cea1698b56e4299d95446a1f7b90a2)
Comment 14 Peter Bergner 2022-08-30 01:14:44 UTC
Fixed everywhere.