@@ -1290,6 +1290,24 @@ (define_predicate "mma_disassemble_output_operand"
return vsx_register_operand (op, mode);
})
+;; Return 1 if this operand is lowpart subreg
+(define_predicate "lowpart_subreg_operand"
+ (match_code "subreg,reg")
+{
+ if (REG_P (op))
+ return 1;
+
+ rtx inner_reg = SUBREG_REG (op);
+ if (!REG_P (inner_reg))
+ return 0;
+
+ machine_mode inner_mode = GET_MODE (inner_reg);
+ if (SUBREG_BYTE (op) != subreg_lowpart_offset (mode, inner_mode))
+ return 0;
+
+ return 1;
+})
+
;; Return true if operand is an operator used in rotate-and-mask instructions.
(define_predicate "rotate_mask_operator"
(match_code "rotate,ashift,lshiftrt"))
@@ -4325,6 +4325,40 @@ (define_insn "*rotldi3_insert_7"
[(set_attr "type" "insert")
(set_attr "size" "64")])
+(define_insn "rlwinm_lowpart_mask"
+ [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
+ (and:DI
+ (subreg:DI
+ (match_operator:SI 4 "rotate_mask_operator"
+ [(match_operand:SI 1 "lowpart_subreg_operand" "r")
+ (match_operand:SI 2 "const_int_operand" "n")]) 0)
+ (match_operand:DI 3 "const_int_operand" "n")))]
+ "TARGET_POWERPC64 && (UINTVAL (operands[3]) >> 32) == 0
+ && rs6000_is_valid_shift_mask (operands[3], operands[4], SImode)"
+{
+ return rs6000_insn_for_shift_mask (SImode, operands, false);
+}
+ [(set_attr "type" "shift")])
+
+(define_insn "rlwinm_mask_<code>"
+ [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
+ (and:DI
+ (plus_ior_xor:DI
+ (ashift:DI
+ (subreg:DI
+ (match_operator:SI 4 "rotate_mask_operator"
+ [(match_operand:SI 1 "lowpart_subreg_operand" "r")
+ (match_operand:SI 2 "const_int_operand" "n")]) 0)
+ (const_int 32))
+ (zero_extend:DI (match_dup 4)))
+ (match_operand:DI 3 "const_int_operand" "n")))]
+ "TARGET_POWERPC64
+ && (UINTVAL (operands[3]) & 0xffffffff80000001ULL) == 0xffffffff80000001ULL
+ && rs6000_is_valid_mask (operands[3], NULL, NULL, SImode)"
+{
+ return rs6000_insn_for_shift_mask (SImode, operands, false);
+}
+ [(set_attr "type" "shift")])
; This handles the important case of multiple-precision shifts. There is
; no canonicalization rule for ASHIFT vs. LSHIFTRT, so two patterns.
@@ -2,12 +2,12 @@
/* { dg-options "-O2" } */
/* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 6739 { target ilp32 } } } */
-/* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 9716 { target lp64 } } } */
+/* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 8164 { target lp64 } } } */
/* { dg-final { scan-assembler-times {(?n)^\s+blr} 3375 } } */
-/* { dg-final { scan-assembler-times {(?n)^\s+rldicl} 3081 { target lp64 } } } */
+/* { dg-final { scan-assembler-times {(?n)^\s+rldicl} 1538 { target lp64 } } } */
/* { dg-final { scan-assembler-times {(?n)^\s+rlwinm} 3197 { target ilp32 } } } */
-/* { dg-final { scan-assembler-times {(?n)^\s+rlwinm} 3093 { target lp64 } } } */
+/* { dg-final { scan-assembler-times {(?n)^\s+rlwinm} 3084 { target lp64 } } } */
/* { dg-final { scan-assembler-times {(?n)^\s+rotlwi} 154 } } */
/* { dg-final { scan-assembler-times {(?n)^\s+srwi} 13 { target ilp32 } } } */
/* { dg-final { scan-assembler-times {(?n)^\s+srdi} 13 { target lp64 } } } */
new file mode 100644
@@ -0,0 +1,47 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -save-temps" } */
+
+typedef unsigned long long u64;
+typedef unsigned int u32;
+#define NOINLE __attribute__ ((noinline))
+#define V (0x9753)
+
+#define MASK 0xffffffffe0000003ULL
+#define N 4
+#define LMASK 0xfffff00
+
+u64 NOINLE
+test_rlwinm_lowpart_mask (u32 v)
+{
+ u32 v1 = ((v << N) | (v >> (32 - N))) & LMASK;
+ return (u64)v1;
+}
+
+u64 NOINLE
+test_rlwinm_mask (u32 v)
+{
+ u32 v1 = ((v << N) | (v >> (32 - N)));
+ u64 v2 = (u64) v1 | ((u64) v1 << 32);
+ return v2 & MASK;
+}
+
+/* { dg-final { scan-assembler-times {\mrlwinm\M} 2 { target has_arch_ppc64 } } } */
+
+#define RLWINM_L(v, n) \
+ ((((v & 0xffffffffLL) << n) | ((v & 0xffffffffLL) >> (32 - n))) \
+ & 0xffffffffLL)
+#define RLWINM_MASK(v, n, m) (((RLWINM_L (v, n) << 32) | (RLWINM_L (v, n))) & m)
+
+u64 v_low_mask = RLWINM_MASK (V, N, LMASK);
+u64 v_mask = RLWINM_MASK (V, N, MASK);
+
+int
+main ()
+{
+ u64 v = V;
+ if (test_rlwinm_lowpart_mask (v) != v_low_mask
+ || test_rlwinm_mask (v) != v_mask)
+ __builtin_abort ();
+
+ return 0;
+}