]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
expand: Use rtx_cost directly instead of gen_move_insn for canonicalize_comparison.
authorAndrew Pinski <quic_apinski@quicinc.com>
Tue, 20 May 2025 21:48:58 +0000 (14:48 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Thu, 22 May 2025 13:09:46 +0000 (06:09 -0700)
This is the first part in fixing PR target/120372.
The current code for canonicalize_comparison, uses gen_move_insn and rtx_cost to find
out the cost of generating a constant. This is ok in most cases except sometimes
the comparison instruction can handle different constants than a simple set
intruction can do. This changes to use rtx_cost directly with the outer being COMPARE
just like how prepare_cmp_insn handles that.

Note this is also a small speedup and small memory improvement because we are not creating
a move for the constant any more. Since we are not creating a psedu-register any more, this
also removes the check on that.

Also adds a dump so we can see why one choice was chosen over the other.

Build and tested for aarch64-linux-gnu.

gcc/ChangeLog:

* expmed.cc (canonicalize_comparison): Use rtx_cost directly
instead of gen_move_insn. Print out the choice if dump is enabled.

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

index 72dbafe5d9f81ed951fbe064a0a62b1816af3b92..d5da199d033dd6cf762f82da72f97cc7cdc23e9e 100644 (file)
@@ -6408,18 +6408,25 @@ canonicalize_comparison (machine_mode mode, enum rtx_code *code, rtx *imm)
   if (overflow)
     return;
 
-  /* The following creates a pseudo; if we cannot do that, bail out.  */
-  if (!can_create_pseudo_p ())
-    return;
-
-  rtx reg = gen_rtx_REG (mode, LAST_VIRTUAL_REGISTER + 1);
   rtx new_imm = immed_wide_int_const (imm_modif, mode);
 
-  rtx_insn *old_rtx = gen_move_insn (reg, *imm);
-  rtx_insn *new_rtx = gen_move_insn (reg, new_imm);
+  int old_cost = rtx_cost (*imm, mode, COMPARE, 0, true);
+  int new_cost = rtx_cost (new_imm, mode, COMPARE, 0, true);
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    {
+      fprintf (dump_file, ";; cmp: %s, old cst: ",
+              GET_RTX_NAME (*code));
+      print_rtl (dump_file, *imm);
+      fprintf (dump_file, " new cst: ");
+      print_rtl (dump_file, new_imm);
+      fprintf (dump_file, "\n");
+      fprintf (dump_file, ";; old cst cost: %d, new cst cost: %d\n",
+              old_cost, new_cost);
+    }
 
   /* Update the immediate and the code.  */
-  if (insn_cost (old_rtx, true) > insn_cost (new_rtx, true))
+  if (old_cost > new_cost)
     {
       *code = equivalent_cmp_code (*code);
       *imm = new_imm;