After my other patch, I decided to write a test case with an illegal constant operand value to a built-in to see what the results would be. Without my other patch, we fail to catch the illegal use and emit an invalid rtl insn and hit an unrecognizable insn ICE. With my previous patch, we correctly flag the use as invalid, but end up ICEing anyway, because we don't return the correct return value (const0_rtx) to signify we had an error.
rs6000: Fix ICE for invalid constants in built-in functions For invalid constant operand values used in built-in functions, return const0_rtx to signify an error occurred during expansion. Bootstrapped and retested on powerlc64le-linux with no regressions. Ok for trunk and backports after some trunk burn-in time? Peter gcc/ * config/rs6000/rs6000-builtin.cc (rs6000_expand_builtin): Return const0_rtx when there is an error. gcc/testsuite/ * gcc.target/powerpc/mma-builtin-error.c: New test. diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc index bdf2fa0b680..111802381ac 100644 --- a/gcc/config/rs6000/rs6000-builtin.cc +++ b/gcc/config/rs6000/rs6000-builtin.cc @@ -3459,7 +3459,7 @@ rs6000_expand_builtin (tree exp, rtx target, rtx /* subtarget */, error ("argument %d must be a literal between 0 and %d," " inclusive", bifaddr->restr_opnd[i], p); - return CONST0_RTX (mode[0]); + return const0_rtx; } break; } @@ -3476,7 +3476,7 @@ rs6000_expand_builtin (tree exp, rtx target, rtx /* subtarget */, " inclusive", bifaddr->restr_opnd[i], bifaddr->restr_val1[i], bifaddr->restr_val2[i]); - return CONST0_RTX (mode[0]); + return const0_rtx; } break; } @@ -3493,7 +3493,7 @@ rs6000_expand_builtin (tree exp, rtx target, rtx /* subtarget */, "between %d and %d, inclusive", bifaddr->restr_opnd[i], bifaddr->restr_val1[i], bifaddr->restr_val2[i]); - return CONST0_RTX (mode[0]); + return const0_rtx; } break; } @@ -3509,7 +3509,7 @@ rs6000_expand_builtin (tree exp, rtx target, rtx /* subtarget */, "literal %d", bifaddr->restr_opnd[i], bifaddr->restr_val1[i], bifaddr->restr_val2[i]); - return CONST0_RTX (mode[0]); + return const0_rtx; } break; } diff --git a/gcc/testsuite/gcc.target/powerpc/mma-builtin-error.c b/gcc/testsuite/gcc.target/powerpc/mma-builtin-error.c new file mode 100644 index 00000000000..a87a1570925 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/mma-builtin-error.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power10" } */ + +typedef unsigned char vec_t __attribute__((vector_size(16))); + +void +foo (__vector_quad *dst, vec_t vec0, vec_t vec1) /* { dg-error "argument 5 must be a literal between 0 and 15, inclusive" } */ +{ + __builtin_mma_pmxvi8ger4 (dst, vec0, vec1, 15, 15, -1); +}