rs6000: Fix ICE for invalid constants in built-in functions

Message ID c04663ca-1fb4-4f7d-a981-cb3604415aed@linux.ibm.com
State Committed
Commit 0696af74b3392e2178215607337b116d1bb53e34
Headers
Series rs6000: Fix ICE for invalid constants in built-in functions |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Peter Bergner Jan. 13, 2025, 9:59 p.m. UTC
  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.
  

Comments

Peter Bergner Jan. 16, 2025, 4:58 p.m. UTC | #1
On 1/13/25 3:59 PM, Peter Bergner wrote:
> 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?

Approved offline by Segher, so I pushed the commit.
I'll let it bake on trunk for a bit before backporting.

Peter
  

Patch

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);
+}