]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
loop-invariant: Treat inline-asm conditional trapping [PR102150]
authorAndrew Pinski <quic_apinski@quicinc.com>
Wed, 12 Feb 2025 05:00:06 +0000 (21:00 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Wed, 12 Feb 2025 22:34:58 +0000 (14:34 -0800)
So inline-asm is known not to trap BUT it can have undefined behavior
if made executed speculatively. This fixes the loop invariant pass to
treat it similarly as trapping cases. If the inline-asm could be executed
always, then it will be pulled out of the loop; otherwise it will be kept
inside the loop.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

PR rtl-optimization/102150
* loop-invariant.cc (find_invariant_insn): Treat inline-asm similar to
trapping instruction and only move them if always executed.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/loop-invariant.cc

index bcb52bb9c76e7b4061da226b4f0a472638aaf191..236d5ee70eee8e1cdd38cfcbfd2eee7b9da6003a 100644 (file)
@@ -1123,6 +1123,11 @@ find_invariant_insn (rtx_insn *insn, bool always_reached, bool always_executed)
   if (may_trap_or_fault_p (PATTERN (insn)) && !always_reached)
     return;
 
+  /* inline-asm that is not always executed cannot be moved
+     as it might conditionally trap. */
+  if (!always_reached && asm_noperands (PATTERN (insn)) >= 0)
+    return;
+
   depends_on = BITMAP_ALLOC (NULL);
   if (!check_dependencies (insn, depends_on))
     {