;; In order to enable using a peephole2 for combining div/mod to eliminate the
;; mod, prefer putting the result of mod into a different register
(define_insn "*mod<mode>3"
- [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r")
- (mod:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
- (match_operand:GPR 2 "gpc_reg_operand" "r")))]
+ [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r,r")
+ (mod:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+ (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
"TARGET_MODULO"
"mods<wd> %0,%1,%2"
[(set_attr "type" "div")
(define_insn "umod<mode>3"
- [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r")
- (umod:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
- (match_operand:GPR 2 "gpc_reg_operand" "r")))]
+ [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r,r")
+ (umod:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+ (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
"TARGET_MODULO"
"modu<wd> %0,%1,%2"
[(set_attr "type" "div")
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
+
+/* Verify r3 is used as source and target, no copy inserted. */
+
+long foo (long a, long b)
+{
+ return (a % b);
+}
+
+unsigned long foo2 (unsigned long a, unsigned long b)
+{
+ return (a % b);
+}
+
+/* { dg-final { scan-assembler-not {\mmr\M} } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
+
+/* Verify peephole fires to combine div/mod using same opnds. */
+
+long foo (long a, long b)
+{
+ long x, y;
+
+ x = a / b;
+ y = a % b;
+ return (x + y);
+}
+
+unsigned long foo2 (unsigned long a, unsigned long b)
+{
+ unsigned long x, y;
+
+ x = a / b;
+ y = a % b;
+ return (x + y);
+}
+
+/* { dg-final { scan-assembler-not {\mmodsd\M} } } */
+/* { dg-final { scan-assembler-not {\mmodud\M} } } */