From dc6b949c553a3be1ce4d6671fb8a9de213ede114 Mon Sep 17 00:00:00 2001
From: Andrew Pinski <quic_apinski@quicinc.com>
Date: Tue, 28 Jan 2025 12:00:06 -0800
Subject: [PATCH] split-path: Small fix for poor_ifcvt_pred (tsvc s258)
 [PR118505]

After r15-3436-gb2b20b277988ab, poor_ifcvt_pred returns false for
the case where the statement could trap but in this case trapping
instructions cannot be made unconditional so it is a poor ifcvt.

This fixes a small preformance regression with TSVC s258 at
`-O3 -ftrapping-math` on aarch64 where ifcvt would not happen
and we would still have a branch.

On a specific aarch64, we go from 0.145s down to 0.118s.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	PR tree-optimization/118505
	* gimple-ssa-split-paths.cc (poor_ifcvt_pred): Return
	true for trapping statements.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/gimple-ssa-split-paths.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/gimple-ssa-split-paths.cc b/gcc/gimple-ssa-split-paths.cc
index 7c5bc1d842c0..9db73fdcc6d4 100644
--- a/gcc/gimple-ssa-split-paths.cc
+++ b/gcc/gimple-ssa-split-paths.cc
@@ -160,6 +160,11 @@ poor_ifcvt_pred (basic_block pred, basic_block bb)
   gimple *stmt = last_and_only_stmt (pred);
   if (!stmt || gimple_code (stmt) != GIMPLE_ASSIGN)
     return true;
+
+  /* If the statement could trap, then this is a poor ifcvt candidate. */
+  if (gimple_could_trap_p (stmt))
+    return true;
+
   tree_code code = gimple_assign_rhs_code (stmt);
   if (poor_ifcvt_candidate_code (code))
     return true;
-- 
GitLab