Skip to content

Commit bcc5054

Browse files
committed
aarch64: Emit csinv again for a ? ~b : b [PR110986]
After r14-3110-g7fb65f10285, the canonical form for `a ? ~b : b` changed to be `-(a) ^ b` that means for aarch64 we need to add a few new insn patterns to be able to catch this and change it to be what is the canonical form for the aarch64 backend. A secondary pattern was needed to support a zero_extended form too; this adds a testcase for all 3 cases. Bootstrapped and tested on aarch64-linux-gnu with no regressions. PR target/110986 gcc/ChangeLog: * config/aarch64/aarch64.md (*cmov<mode>_insn_insv): New pattern. (*cmov_uxtw_insn_insv): Likewise. gcc/testsuite/ChangeLog: * gcc.target/aarch64/cond_op-1.c: New test.
1 parent c9ae68f commit bcc5054

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

gcc/config/aarch64/aarch64.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,6 +4413,53 @@
44134413
[(set_attr "type" "csel")]
44144414
)
44154415

4416+
;; There are two canonical forms for `cmp ? ~a : a`.
4417+
;; This is the second form and is here to help combine.
4418+
;; Support `-(cmp) ^ a` into `cmp ? ~a : a`
4419+
;; The second pattern is to support the zero extend'ed version.
4420+
4421+
(define_insn_and_split "*cmov<mode>_insn_insv"
4422+
[(set (match_operand:GPI 0 "register_operand" "=r")
4423+
(xor:GPI
4424+
(neg:GPI
4425+
(match_operator:GPI 1 "aarch64_comparison_operator"
4426+
[(match_operand 2 "cc_register" "") (const_int 0)]))
4427+
(match_operand:GPI 3 "general_operand" "r")))]
4428+
""
4429+
"#"
4430+
"&& true"
4431+
[(set (match_dup 0)
4432+
(if_then_else:GPI (match_dup 1)
4433+
(not:GPI (match_dup 3))
4434+
(match_dup 3)))]
4435+
{
4436+
/* After reload this will be a nop due to the constraint. */
4437+
operands[3] = force_reg (<MODE>mode, operands[3]);
4438+
}
4439+
[(set_attr "type" "csel")]
4440+
)
4441+
4442+
(define_insn_and_split "*cmov_uxtw_insn_insv"
4443+
[(set (match_operand:DI 0 "register_operand" "=r")
4444+
(zero_extend:DI
4445+
(xor:SI
4446+
(neg:SI
4447+
(match_operator:SI 1 "aarch64_comparison_operator"
4448+
[(match_operand 2 "cc_register" "") (const_int 0)]))
4449+
(match_operand:SI 3 "general_operand" "r"))))]
4450+
"can_create_pseudo_p ()"
4451+
"#"
4452+
"&& true"
4453+
[(set (match_dup 0)
4454+
(if_then_else:DI (match_dup 1)
4455+
(zero_extend:DI (not:SI (match_dup 3)))
4456+
(zero_extend:DI (match_dup 3))))]
4457+
{
4458+
operands[3] = force_reg (SImode, operands[3]);
4459+
}
4460+
[(set_attr "type" "csel")]
4461+
)
4462+
44164463
;; If X can be loaded by a single CNT[BHWD] instruction,
44174464
;;
44184465
;; A = UMAX (B, X)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2" } */
3+
/* PR target/110986 */
4+
5+
6+
long long full(unsigned a, unsigned b)
7+
{
8+
return a ? ~b : b;
9+
}
10+
unsigned fuu(unsigned a, unsigned b)
11+
{
12+
return a ? ~b : b;
13+
}
14+
long long fllll(unsigned long long a, unsigned long long b)
15+
{
16+
return a ? ~b : b;
17+
}
18+
19+
/* { dg-final { scan-assembler-times "csinv\tw\[0-9\]*" 2 } } */
20+
/* { dg-final { scan-assembler-times "csinv\tx\[0-9\]*" 1 } } */

0 commit comments

Comments
 (0)