[Bug target/93453] PPC: rldimi not taken into account to avoid shift+or

guihaoc at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 23 02:46:17 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93453

--- Comment #6 from HaoChen Gui <guihaoc at gcc dot gnu.org> ---
Sehger,
  Yes, I found that the nonzero_bits doesn't return exact value in other pass.
So calling nonzero_bits in md file is bad as it can't be recognized in other
pass. 
  Right now I want to convert a single pseudo to the pseudo AND with a mask in
combine pass if its nonzero_bits is less than its mode mask and the outer
operation is plus/ior/xor and its one of inner operation is
ashift/lshiftrt/and. Thus it is possible to match rotate and insert pattern.
What's your opinion? Thanks a lot.

(ior:DI (ashift:DI (reg:DI 125)
            (const_int 32 [0x20]))
        (reg:DI 126)))

is converted to

(ior:DI (ashift:DI (reg:DI 125)
                       (const_int 32 [0x20]))
            (and:DI (reg:DI 126)
                    (const_int 4294967295 [0xfffffff]))))


patch.diff

diff --git a/gcc/combine.c b/gcc/combine.c
index 892c834a160..8b72a5ec831 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -11539,6 +11539,26 @@ change_zero_ext (rtx pat)
   return changed;
 }

+/* Convert a psuedo to psuedo AND with a mask if its nonzero_bits is less
+   than its mode mask.  */
+static bool
+pseudo_and_with_mask (rtx *reg)
+{
+  bool changed = false;
+  gcc_assert (REG_P (*reg));
+
+  machine_mode mode = GET_MODE (*reg);
+  unsigned HOST_WIDE_INT nonzero = nonzero_bits (*reg, mode);
+  if (nonzero < GET_MODE_MASK (mode))
+    {
+      rtx x = gen_rtx_AND (mode, *reg, GEN_INT (nonzero));
+      SUBST (*reg, x);
+      changed = true;
+      //fprintf (stdout, "PIX optimization\n");
+    }
+  return changed;
+}
+
 /* Like recog, but we receive the address of a pointer to a new pattern.
    We try to match the rtx that the pointer points to.
    If that fails, we may try to modify or replace the pattern,
@@ -11565,9 +11585,34 @@ recog_for_combine (rtx *pnewpat, rtx_insn *insn, rtx
*pnotes)

   void *marker = get_undo_marker ();
   bool changed = false;
+  //bool PIX_opt = false;

   if (GET_CODE (pat) == SET)
-    changed = change_zero_ext (pat);
+    {
+      rtx src = SET_SRC (pat);
+      if ((GET_CODE (src) == IOR
+          || GET_CODE (src) == XOR
+          || GET_CODE (src) == PLUS)
+         && (((GET_CODE (XEXP (src, 0)) == ASHIFT
+               || GET_CODE (XEXP (src, 0)) == LSHIFTRT
+               || GET_CODE (XEXP (src, 0)) == AND)
+              && REG_P (XEXP (src, 1)))
+             || ((GET_CODE (XEXP (src, 1)) == ASHIFT
+                  || GET_CODE (XEXP (src, 1)) == LSHIFTRT
+                  || GET_CODE (XEXP (src, 1)) == AND)
+                 && REG_P (XEXP (src, 0)))))
+       {
+         changed = REG_P (XEXP (src, 0))
+                   ? pseudo_and_with_mask (&XEXP (SET_SRC (pat), 0))
+                   : pseudo_and_with_mask (&XEXP (SET_SRC (pat), 1));
+         if (changed)
+           {
+             maybe_swap_commutative_operands (SET_SRC (pat));
+             //PIX_opt = true;
+           }
+       }
+      changed |= change_zero_ext (pat);
+    }
   else if (GET_CODE (pat) == PARALLEL)
     {
       int i;
@@ -11585,6 +11630,8 @@ recog_for_combine (rtx *pnewpat, rtx_insn *insn, rtx
*pnotes)

       if (insn_code_number < 0)
        undo_to_marker (marker);
+      //else if (PIX_opt)
+       //fprintf (stdout, "PIX applied\n");
     }

   return insn_code_number;


More information about the Gcc-bugs mailing list