https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87532
--- Comment #4 from kelvin at gcc dot gnu.org --- Is this a bug or just "bad documentation"? 64-Bit ELF V2 ABI Specification says vec_extract (v, 3) is equivalent to v[3]. Then it clarifies that vec_extract (arg1, arg2) uses modular arithmetic on arg2 to determine the index position from which to extract the result. If v is vector int, then vec_extract(vi, 10) equals vec_extract (vi, 10%4) which is vec_extract (vi, 2). I am familiar with the error messages reported for the test programs attached to this problem report. The error messages are misleading and inconsistent with actual implementation. The following test reveals some of the current implementation behaviors. #include <stdio.h> #include "altivec.h" vector int vi; extern void clobber (); #ifdef ILLEGAL_CODE //__attribute ((noinline)) int doextractbybuiltin (vector int vi, int index) { /* Builtin expansion of vec_extract requires that index be a compile-time constant. The generated error message says the selector must be an integer constant in the range 0..3, which is not accurate. */ return vec_extract (vi, index); } #endif //__attribute ((noinline)) int doextractbybrace (vector int vi, int index) { return vi [index]; } int main (int argc, char *argv) { vi[0] = 0x00ff00; vi[1] = 0x01ff01; vi[2] = 0x02ff02; vi[3] = 0x03ff03; printf ("a: 0x%x\n", doextractbybrace (vi, 3)); // outputs 0x3ff03 printf ("b: 0x%x\n", doextractbybrace (vi, 10)); // outputs 0 // (undefined behavior?) // which, by the way, is not the same as vec_extract (vi, 10) #ifdef ILLEGAL_CODE printf ("c: 0x%x\n", doextractbybuiltin (vi, 3)); printf ("d: 0x%x\n", doextractbybuiltin (vi, 10)); #endif printf ("e: 0x%x\n", vi[3]); // outputs 0x3ff03 printf ("f: 0x%x\n", vi[10]); // outputs 0 (undefined behavior?) printf ("g: 0x%x\n", vec_extract(vi, 3)); // outputs 0x3ff03 printf ("h: 0x%x\n", vec_extract(vi, 10)); // outputs 0x2ff02 } What do we want to change, if anything, about the current implementation? My inclination: Change the generated error message to require selector to be a constant (but not specify that it be in the range 0..3 Change the ABI description to not claim that vec_extract (v, i) is equivalent to v[i] and clarify that i must be a constant. Do we want to do more?