Skip to content

Commit

Permalink
RISC-V: Produce better code with complex constants [PR95632] [PR106602]
Browse files Browse the repository at this point in the history
gcc/Changelog:
	PR target/95632
	PR target/106602
	* config/riscv/riscv.md: New pattern to simulate complex
	const_int loads.

gcc/testsuite/ChangeLog:
	* gcc.target/riscv/pr95632.c: New test.
	* gcc.target/riscv/pr106602.c: New test.
  • Loading branch information
rzinsly authored and JeffreyALaw committed Dec 27, 2022
1 parent 7c755fd commit 2e886ee
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gcc/config/riscv/riscv.md
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,23 @@
MAX_MACHINE_MODE, &operands[3], TRUE);
})

;; Pretend to have the ability to load complex const_int in order to get
;; better code generation around them.
;;
;; But avoid constants that are special cased elsewhere.
(define_insn_and_split "*mvconst_internal"
[(set (match_operand:GPR 0 "register_operand" "=r")
(match_operand:GPR 1 "splittable_const_int_operand" "i"))]
"!(p2m1_shift_operand (operands[1]) || high_mask_shift_operand (operands[1]))"
"#"
"&& 1"
[(const_int 0)]
{
riscv_move_integer (operands[0], operands[0], INTVAL (operands[1]),
<MODE>mode, TRUE);
DONE;
})

;; 64-bit integer moves

(define_expand "movdi"
Expand Down
14 changes: 14 additions & 0 deletions gcc/testsuite/gcc.target/riscv/pr106602.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* { dg-do compile { target { riscv64*-*-* } } } */
/* { dg-options "-O2" } */

unsigned long
foo2 (unsigned long a)
{
return (unsigned long)(unsigned int) a << 6;
}

/* { dg-final { scan-assembler-times "slli\t" 1 } } */
/* { dg-final { scan-assembler-times "srli\t" 1 } } */
/* { dg-final { scan-assembler-not "\tli\t" } } */
/* { dg-final { scan-assembler-not "addi\t" } } */
/* { dg-final { scan-assembler-not "and\t" } } */
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/pr95632.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* { dg-options "-O2" } */

unsigned short
foo (unsigned short crc)
{
crc ^= 0x4002;
crc >>= 1;
crc |= 0x8000;

return crc;
}

/* { dg-final { scan-assembler-times "srli\t" 1 } } */
/* { dg-final { scan-assembler-not "slli\t" } } */

0 comments on commit 2e886ee

Please sign in to comment.