[PATCH] aarch64: Fix ICE on discarded intrinsic result [PR127771]

dhruvc@nvidia.com dhruvc@nvidia.com
Fri Oct 9 09:16:13 GMT 2026


From: Dhruv Chawla <dhruvc@nvidia.com>

r17-4816-gb24418a2212866 gives a call whose result is discarded a placeholder
lhs using create_tmp_var, which gives a VAR_DECL. This ends up setting
ssa_renaming_needed and the subsequent fold passes do not set TODO_update_ssa,
so execute_todo ICEs.

This needs the fold to run after SSA construction. In the testcase the second
operand is not yet a constant when intrinsics are first folded from
gimple-low, so the fold only succeeds once CCP has executed.

Make the placeholder an SSA name when the function is already in SSA form, and
release it again when the fold leaves it untouched.

Bootstrapped and regtested on aarch64-linux-gnu.

Signed-off-by: Dhruv Chawla <dhruvc@nvidia.com>

gcc/ChangeLog:

	PR target/127771
	* config/aarch64/aarch64-acle-builtins.cc: Include ssa.h.
	(gimple_folder::fold): Make an SSA name for the placeholder once
	the function is in SSA form and release it when unused.

gcc/testsuite/ChangeLog:

	PR target/127771
	* gcc.target/aarch64/sve/acle/general/pr127771.c: New test.
---
 gcc/config/aarch64/aarch64-acle-builtins.cc   | 37 +++++++++++++++----
 .../aarch64/sve/acle/general/pr127771.c       | 12 ++++++
 2 files changed, 42 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr127771.c

diff --git a/gcc/config/aarch64/aarch64-acle-builtins.cc b/gcc/config/aarch64/aarch64-acle-builtins.cc
index 5abcc01b96bf..447c34017ccb 100644
--- a/gcc/config/aarch64/aarch64-acle-builtins.cc
+++ b/gcc/config/aarch64/aarch64-acle-builtins.cc
@@ -46,6 +46,7 @@
 #include "gimple-fold.h"
 #include "langhooks.h"
 #include "stringpool.h"
+#include "ssa.h"
 #include "attribs.h"
 #include "value-range.h"
 #include "tree-ssanames.h"
@@ -3141,17 +3142,39 @@ gimple_folder::fold ()
 
   /* Create a placeholder variable for the result.
      This allows implementers of `fold` to assume `lhs` will never be null.
-     If the result is unused, it will be optimized away later.  */
+     If the result is unused, it will be optimized away later.
+
+     Once the function is in SSA form the placeholder has to be an SSA name, as
+     subsequent fold passes do not set TODO_update_ssa which causes an ICE in
+     execute_todo.  */
+  tree placeholder = NULL_TREE;
   if (!lhs && TREE_TYPE (gimple_call_fntype (call)) != void_type_node)
-    lhs = create_tmp_var (TREE_TYPE (gimple_call_fntype (call)));
+    {
+      tree type = TREE_TYPE (gimple_call_fntype (call));
+      if (cfun->curr_properties & PROP_ssa)
+	lhs = placeholder = make_ssa_name (type);
+      else
+	lhs = create_tmp_var (type);
+    }
 
   /* First try some simplifications that are common to many functions.  */
-  if (auto *call = redirect_pred_x ())
-    return call;
-  if (auto *call = fold_pfalse ())
-    return call;
+  gimple *stmt = redirect_pred_x ();
+  if (!stmt)
+    stmt = fold_pfalse ();
+  if (!stmt)
+    stmt = base->fold (*this);
+
+  /* Release a placeholder that nothing defines and nothing uses, because
+     gimple_build_assign does not set the definition until insertion and
+     convert_and_fold returns a different statement from the one it inserts.  */
+  if (placeholder && (!stmt || gimple_get_lhs (stmt) != placeholder))
+    {
+      gimple *def = SSA_NAME_DEF_STMT (placeholder);
+      if (has_zero_uses (placeholder) && (!def || gimple_nop_p (def)))
+	release_ssa_name (placeholder);
+    }
 
-  return base->fold (*this);
+  return stmt;
 }
 
 /* Force EXPR to be a GIMPLE value, putting it into a new variable if
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr127771.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr127771.c
new file mode 100644
index 000000000000..9a3fb11dc018
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr127771.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+#include <arm_sve.h>
+
+/* PR target/127771  */
+
+void
+g (svbool_t p, svuint32_t a)
+{
+  svmul_x (p, a, svdup_u32 (1));
+}
-- 
2.43.0



More information about the Gcc-patches mailing list