]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Check the mode of SVE ACLE function results
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 4 Aug 2025 10:45:36 +0000 (11:45 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Mon, 4 Aug 2025 10:45:36 +0000 (11:45 +0100)
After previous patches, we should always get a VNx16BI result
for ACLE intrinsics that return svbool_t.  This patch adds
an assert that checks a more general condition than that.

gcc/
* config/aarch64/aarch64-sve-builtins.cc
(function_expander::expand): Assert that the return value
has an appropriate mode.

gcc/config/aarch64/aarch64-sve-builtins.cc

index 01833a8de732cdf13d973168a1adcb9706967134..e394c9a84a040cb133d73b5cf6a66e79603b0c18 100644 (file)
@@ -4593,7 +4593,27 @@ function_expander::expand ()
       gcc_assert (args.last ()->mode == DImode);
       emit_move_insn (gen_rtx_REG (DImode, FPM_REGNUM), args.last ());
     }
-  return base->expand (*this);
+  rtx result = base->expand (*this);
+  if (function_returns_void_p ())
+    gcc_assert (result == const0_rtx);
+  else
+    {
+      auto expected_mode = result_mode ();
+      if (GET_MODE_CLASS (expected_mode) == MODE_INT)
+       /* Scalar integer constants don't store a mode.
+
+          It's OK for a variable result to have a different mode from the
+          function return type.  In particular, some functions that return int
+          expand into instructions that have a DImode result, with all 64 bits
+          of the DImode being well-defined (usually zero).  */
+       gcc_assert (CONST_SCALAR_INT_P (result)
+                   || GET_MODE_CLASS (GET_MODE (result)) == MODE_INT);
+      else
+       /* In other cases, the return value should have the same mode
+          as the return type.  */
+       gcc_assert (GET_MODE (result) == expected_mode);
+    }
+  return result;
 }
 
 /* Return a structure type that contains a single field of type FIELD_TYPE.