Commit graph

205663 commits

Author SHA1 Message Date
Maciej W. Rozycki
2f0c6252f4 RISC-V: Avoid extraneous integer comparison for FP comparisons
We have floating-point coditional-set machine instructions for a subset
of FP comparisons, so avoid going through a comparison against constant
zero in `riscv_expand_float_scc' where not necessary, preventing an
extraneous RTL instruction from being produced that counts against the
cost of the replacement branchless code sequence in if-conversion, e.g.:

(insn 29 6 30 2 (set (reg:DI 142)
        (ge:DI (reg/v:DF 135 [ w ])
            (reg/v:DF 136 [ x ]))) 297 {*cstoredfdi4}
     (nil))
(insn 30 29 31 2 (set (reg:DI 143)
        (ne:DI (reg:DI 142)
            (const_int 0 [0]))) 319 {*sne_zero_didi}
     (nil))
(insn 31 30 32 2 (set (reg:DI 141)
        (reg:DI 143)) 206 {*movdi_64bit}
     (nil))
(insn 32 31 33 2 (set (reg:DI 144)
        (neg:DI (reg:DI 141))) 15 {negdi2}
     (nil))
(insn 33 32 34 2 (set (reg:DI 145)
        (and:DI (reg:DI 144)
            (reg/v:DI 137 [ y ]))) 102 {*anddi3}
     (nil))
(insn 34 33 35 2 (set (reg:DI 146)
        (not:DI (reg:DI 144))) 111 {one_cmpldi2}
     (nil))
(insn 35 34 36 2 (set (reg:DI 147)
        (and:DI (reg:DI 146)
            (reg/v:DI 138 [ z ]))) 102 {*anddi3}
     (nil))
(insn 36 35 21 2 (set (reg/v:DI 138 [ z ])
        (ior:DI (reg:DI 145)
            (reg:DI 147))) 105 {iordi3}
     (nil))

where the second insn effectively just copies its input.  This now gets
simplified to:

(insn 29 6 30 2 (set (reg:DI 141)
        (ge:DI (reg/v:DF 135 [ w ])
            (reg/v:DF 136 [ x ]))) 297 {*cstoredfdi4}
     (nil))
(insn 30 29 31 2 (set (reg:DI 142)
        (neg:DI (reg:DI 141))) 15 {negdi2}
     (nil))
(insn 31 30 32 2 (set (reg:DI 143)
        (and:DI (reg:DI 142)
            (reg/v:DI 137 [ y ]))) 102 {*anddi3}
     (nil))
(insn 32 31 33 2 (set (reg:DI 144)
        (not:DI (reg:DI 142))) 111 {one_cmpldi2}
     (nil))
(insn 33 32 34 2 (set (reg:DI 145)
        (and:DI (reg:DI 144)
            (reg/v:DI 138 [ z ]))) 102 {*anddi3}
     (nil))
(insn 34 33 21 2 (set (reg/v:DI 138 [ z ])
        (ior:DI (reg:DI 143)
            (reg:DI 145))) 105 {iordi3}
     (nil))

lowering the cost of the code sequence produced (even though combine
would swallow the second insn anyway).

We still need to produce a comparison against constant zero where the
instruction following a floating-point coditional-set operation is a
branch, so add canonicalization to `riscv_expand_conditional_branch'
instead.

	gcc/
	* config/riscv/riscv.cc (riscv_emit_float_compare) <NE>: Handle
	separately.
	<EQ, LE, LT, GE, GT>: Return operands supplied as is.
	(riscv_emit_binary): Call `riscv_emit_binary' directly rather
	than going through a temporary register for word-mode targets.
	(riscv_expand_conditional_branch): Canonicalize the comparison
	if not against constant zero.
2023-11-22 01:18:30 +00:00
Maciej W. Rozycki
2f825475b2 RISC-V: Provide FP conditional-branch instructions for if-conversion
Do not expand floating-point conditional-branch RTL instructions right
away that use a comparison operation that is either directly available
as a machine conditional-set instruction or is NE, which can be emulated
by EQ.  This is so that if-conversion sees them in their original form
and can produce fewer operations tried in a branchless code sequence
compared to when such an instruction has been already converted to a
sequence of a floating-point conditional-set RTL instruction followed by
an integer conditional-branch RTL instruction.  Split any floating-point
conditional-branch RTL instructions still remaining after reload then.

Adjust the testsuite accordingly: since the middle end uses the inverse
condition internally, an inverse conditional-set instruction may make it
to assembly output and also `cond_move_process_if_block' will be used by
if-conversion rather than `noce_process_if_block', because the latter
function not yet been updated to handle inverted conditions.

	gcc/
	* config/riscv/predicates.md (ne_operator): New predicate.
	* config/riscv/riscv.cc (riscv_insn_cost): Handle branches on a
	floating-point condition.
	* config/riscv/riscv.md (@cbranch<mode>4): Rename expander to...
	(@cbranch<ANYF:mode>4): ... this.  Only expand the RTX via
	`riscv_expand_conditional_branch' for `!signed_order_operator'
	operators, otherwise let it through.
	(*cbranch<ANYF:mode>4, *cbranch<ANYF:mode>4): New insns and
	splitters.

	gcc/testsuite/
	* gcc.target/riscv/movdifge-sfb.c: Reject "if-conversion
	succeeded through" rather than accepting it.
	* gcc.target/riscv/movdifge-thead.c: Likewise.
	* gcc.target/riscv/movdifge-ventana.c: Likewise.
	* gcc.target/riscv/movdifge-zicond.c: Likewise.
	* gcc.target/riscv/movdifgt-sfb.c: Likewise.
	* gcc.target/riscv/movdifgt-thead.c: Likewise.
	* gcc.target/riscv/movdifgt-ventana.c: Likewise.
	* gcc.target/riscv/movdifgt-zicond.c: Likewise.
	* gcc.target/riscv/movdifle-sfb.c: Likewise.
	* gcc.target/riscv/movdifle-thead.c: Likewise.
	* gcc.target/riscv/movdifle-ventana.c: Likewise.
	* gcc.target/riscv/movdifle-zicond.c: Likewise.
	* gcc.target/riscv/movdiflt-sfb.c: Likewise.
	* gcc.target/riscv/movdiflt-thead.c: Likewise.
	* gcc.target/riscv/movdiflt-ventana.c: Likewise.
	* gcc.target/riscv/movdiflt-zicond.c: Likewise.
	* gcc.target/riscv/movsifge-sfb.c: Likewise.
	* gcc.target/riscv/movsifge-thead.c: Likewise.
	* gcc.target/riscv/movsifge-ventana.c: Likewise.
	* gcc.target/riscv/movsifge-zicond.c: Likewise.
	* gcc.target/riscv/movsifgt-sfb.c: Likewise.
	* gcc.target/riscv/movsifgt-thead.c: Likewise.
	* gcc.target/riscv/movsifgt-ventana.c: Likewise.
	* gcc.target/riscv/movsifgt-zicond.c: Likewise.
	* gcc.target/riscv/movsifle-sfb.c: Likewise.
	* gcc.target/riscv/movsifle-thead.c: Likewise.
	* gcc.target/riscv/movsifle-ventana.c: Likewise.
	* gcc.target/riscv/movsifle-zicond.c: Likewise.
	* gcc.target/riscv/movsiflt-sfb.c: Likewise.
	* gcc.target/riscv/movsiflt-thead.c: Likewise.
	* gcc.target/riscv/movsiflt-ventana.c: Likewise.
	* gcc.target/riscv/movsiflt-zicond.c: Likewise.
	* gcc.target/riscv/smax-ieee.c: Also accept FLT.D.
	* gcc.target/riscv/smaxf-ieee.c: Also accept FLT.S.
	* gcc.target/riscv/smin-ieee.c: Also accept FGT.D.
	* gcc.target/riscv/sminf-ieee.c: Also accept FGT.S.
2023-11-22 01:18:30 +00:00
Maciej W. Rozycki
37ff43c273 RISC-V: Also allow FP conditions in `riscv_expand_conditional_move'
In `riscv_expand_conditional_move' we only let integer conditions
through at the moment, even though code has already been prepared to
handle floating-point conditions as well.

Lift this restriction and only bail out if a non-word-mode integer
condition has been requested, as we cannot handle this specific case
owing to machine instruction set restriction.  We already take care of
the non-integer, non-floating-point case later on.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Don't
	bail out in floating-point conditions.
2023-11-22 01:18:29 +00:00
Maciej W. Rozycki
7e126d8d0f RISC-V: Only use SUBREG if applicable in `riscv_expand_float_scc'
A subsequent change to enable the processing of conditional moves on a
floating-point condition by `riscv_expand_conditional_move' will cause
`riscv_expand_float_scc' to be called for word-mode target RTX with RV64
targets.  In that case an invalid insn such as:

(insn 25 24 0 (set (reg:DI 141)
        (subreg:SI (reg:DI 143) 0)) -1
     (nil))

would be produced, which would crash the compiler later on.  Since the
output operand of the SET operation to be produced already has the same
mode as the input operand does, just omit the use of SUBREG and assign
directly.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_float_scc): Suppress the
	use of SUBREG if the conditional-set target is word-mode.
2023-11-22 01:18:29 +00:00
Maciej W. Rozycki
5e6903ddd3 RISC-V/testsuite: Add branchless cases for generic integer cond adds
Verify, for generic integer conditional-add operations, if-conversion
to trigger via `noce_try_addcc' at the respective sufficiently high
`-mbranch-cost=' settings that make branchless code sequences produced
by if-conversion cheaper than their original branched equivalents, and,
where applicable, that extraneous instructions such as SNEZ, etc. are
not present in output.  Cover all integer relational operations to make
sure no corner case escapes.

The reason to XFAIL SImode tests for RV64 targets is the compiler thinks
it has to sign-extend addends, which causes if-conversion to give up.

	gcc/testsuite/
	* gcc.target/riscv/adddieq.c: New test.
	* gcc.target/riscv/adddige.c: New test.
	* gcc.target/riscv/adddigeu.c: New test.
	* gcc.target/riscv/adddigt.c: New test.
	* gcc.target/riscv/adddigtu.c: New test.
	* gcc.target/riscv/adddile.c: New test.
	* gcc.target/riscv/adddileu.c: New test.
	* gcc.target/riscv/adddilt.c: New test.
	* gcc.target/riscv/adddiltu.c: New test.
	* gcc.target/riscv/adddine.c: New test.
	* gcc.target/riscv/addsieq.c: New test.
	* gcc.target/riscv/addsige.c: New test.
	* gcc.target/riscv/addsigeu.c: New test.
	* gcc.target/riscv/addsigt.c: New test.
	* gcc.target/riscv/addsigtu.c: New test.
	* gcc.target/riscv/addsile.c: New test.
	* gcc.target/riscv/addsileu.c: New test.
	* gcc.target/riscv/addsilt.c: New test.
	* gcc.target/riscv/addsiltu.c: New test.
	* gcc.target/riscv/addsine.c: New test.
2023-11-22 01:18:29 +00:00
Maciej W. Rozycki
bbfe2639e1 RISC-V/testsuite: Add branched cases for generic integer cond adds
Verify, for generic integer conditional-add operations, if-conversion
*not* to trigger at the respective sufficiently low `-mbranch-cost='
settings that make original branched code sequences cheaper than their
branchless equivalents if-conversion would emit.  Cover all integer
relational operations to make sure no corner case escapes.

	gcc/testsuite/
	* gcc.target/riscv/adddibeq.c: New test.
	* gcc.target/riscv/adddibge.c: New test.
	* gcc.target/riscv/adddibgeu.c: New test.
	* gcc.target/riscv/adddibgt.c: New test.
	* gcc.target/riscv/adddibgtu.c: New test.
	* gcc.target/riscv/adddible.c: New test.
	* gcc.target/riscv/adddibleu.c: New test.
	* gcc.target/riscv/adddiblt.c: New test.
	* gcc.target/riscv/adddibltu.c: New test.
	* gcc.target/riscv/adddibne.c: New test.
	* gcc.target/riscv/addsibeq.c: New test.
	* gcc.target/riscv/addsibge.c: New test.
	* gcc.target/riscv/addsibgeu.c: New test.
	* gcc.target/riscv/addsibgt.c: New test.
	* gcc.target/riscv/addsibgtu.c: New test.
	* gcc.target/riscv/addsible.c: New test.
	* gcc.target/riscv/addsibleu.c: New test.
	* gcc.target/riscv/addsiblt.c: New test.
	* gcc.target/riscv/addsibltu.c: New test.
	* gcc.target/riscv/addsibne.c: New test.
2023-11-22 01:18:29 +00:00
Maciej W. Rozycki
40b243c470 RISC-V: Add `addMODEcc' implementation for generic targets
Provide RTL expansion of conditional-add operations for generic targets
using a suitable sequence of base integer machine instructions according
to cost evaluation by if-conversion.  Use existing `-mmovcc' command
line option to enable this transformation.

	gcc/
	* config/riscv/riscv.md (add<mode>cc): New expander.
2023-11-22 01:18:28 +00:00
Maciej W. Rozycki
4111bdf99b RISC-V/testsuite: Add branchless cases for generic integer cond moves
Verify, for generic integer conditional-move operations, if-conversion
to trigger via `noce_try_cmove' at the respective sufficiently high
`-mbranch-cost=' settings that make branchless code sequences produced
by if-conversion cheaper than their original branched equivalents, and,
where applicable, that extraneous instructions such as SNEZ, etc. are
not present in output.  Cover all integer relational operations to make
sure no corner case escapes.

	gcc/testsuite/
	* gcc.target/riscv/movdieq.c: New test.
	* gcc.target/riscv/movdige.c: New test.
	* gcc.target/riscv/movdigeu.c: New test.
	* gcc.target/riscv/movdigt.c: New test.
	* gcc.target/riscv/movdigtu.c: New test.
	* gcc.target/riscv/movdile.c: New test.
	* gcc.target/riscv/movdileu.c: New test.
	* gcc.target/riscv/movdilt.c: New test.
	* gcc.target/riscv/movdiltu.c: New test.
	* gcc.target/riscv/movdine.c: New test.
	* gcc.target/riscv/movsieq.c: New test.
	* gcc.target/riscv/movsige.c: New test.
	* gcc.target/riscv/movsigeu.c: New test.
	* gcc.target/riscv/movsigt.c: New test.
	* gcc.target/riscv/movsigtu.c: New test.
	* gcc.target/riscv/movsile.c: New test.
	* gcc.target/riscv/movsileu.c: New test.
	* gcc.target/riscv/movsilt.c: New test.
	* gcc.target/riscv/movsiltu.c: New test.
	* gcc.target/riscv/movsine.c: New test.
2023-11-22 01:18:28 +00:00
Maciej W. Rozycki
430b9636a5 RISC-V/testsuite: Add branched cases for generic integer cond moves
Verify, for generic integer conditional-move operations, if-conversion
*not* to trigger at the respective sufficiently low `-mbranch-cost='
settings that make original branched code sequences cheaper than their
branchless equivalents if-conversion would emit.  Cover all integer
relational operations to make sure no corner case escapes.

	gcc/testsuite/
	* gcc.target/riscv/movdibeq.c: New test.
	* gcc.target/riscv/movdibge.c: New test.
	* gcc.target/riscv/movdibgeu.c: New test.
	* gcc.target/riscv/movdibgt.c: New test.
	* gcc.target/riscv/movdibgtu.c: New test.
	* gcc.target/riscv/movdible.c: New test.
	* gcc.target/riscv/movdibleu.c: New test.
	* gcc.target/riscv/movdiblt.c: New test.
	* gcc.target/riscv/movdibltu.c: New test.
	* gcc.target/riscv/movdibne.c: New test.
	* gcc.target/riscv/movsibeq.c: New test.
	* gcc.target/riscv/movsibge.c: New test.
	* gcc.target/riscv/movsibgeu.c: New test.
	* gcc.target/riscv/movsibgt.c: New test.
	* gcc.target/riscv/movsibgtu.c: New test.
	* gcc.target/riscv/movsible.c: New test.
	* gcc.target/riscv/movsibleu.c: New test.
	* gcc.target/riscv/movsiblt.c: New test.
	* gcc.target/riscv/movsibltu.c: New test.
	* gcc.target/riscv/movsibne.c: New test.
2023-11-22 01:18:28 +00:00
Maciej W. Rozycki
dc95b338c0 RISC-V: Add `movMODEcc' implementation for generic targets
Provide RTL expansion of conditional-move operations for generic targets
using a suitable sequence of base integer machine instructions according
to cost evaluation by if-conversion.  Add `-mmovcc' command line option
to enable this transformation, off by default.

For the generic sequences small immediates as per the `arith_operand'
predicate are cost-equivalent to registers as we can use them as input,
alternative to a register, to the respective AND[I] machine operations,
however we need to reject immediates fulfilling `lui_operand', because
they would require reloading into a register, making the operation more
costly.  Therefore add `movcc_operand' predicate and use it accordingly.

There is a need to adjust zbs-bext-02.c, which can also serve as emitted
code example, because with certain compilation options an AND operation
can now legitimately appear in output despite BEXT having been produced
as expected, such as with `-march=rv64gc -O2':

foo:
	mv	a3,a0
	li	a5,0
	mv	a0,a1
	li	a2,64
	li	a1,1
.L3:
	sll	a4,a1,a5
	and	a4,a4,a3
	addiw	a5,a5,1
	beq	a4,zero,.L2
	addiw	a0,a0,1
.L2:
	bne	a5,a2,.L3
	ret

vs `-march=rv64gc_zbs -O2':

foo:
	mv	a4,a0
	li	a5,0
	mv	a0,a1
	li	a3,64
.L3:
	bext	a2,a4,a5
	beq	a2,zero,.L2
	addiw	a0,a0,1
.L2:
	addiw	a5,a5,1
	bne	a5,a3,.L3
	ret

and then with `-march=rv64gc -mmovcc -mbranch-cost=7':

foo:
	mv	a6,a0
	li	a4,0
	mv	a0,a1
	li	a7,1
	li	a1,64
.L3:
	sll	a5,a7,a4
	and	a5,a5,a6
	snez	a5,a5
	neg	a5,a5
	not	a2,a5
	addiw	a3,a0,1
	and	a5,a5,a3
	and	a0,a2,a0
	addiw	a4,a4,1
	or	a0,a5,a0
	bne	a4,a1,.L3
	ret

vs `-march=rv64gc_zbs -mmovcc -mbranch-cost=7':

foo:
	mv	a6,a0
	li	a4,0
	mv	a0,a1
	li	a1,64
.L3:
	bext	a5,a6,a4
	neg	a5,a5
	not	a2,a5
	addiw	a3,a0,1
	and	a5,a5,a3
	and	a0,a2,a0
	addiw	a4,a4,1
	or	a0,a5,a0
	bne	a4,a1,.L3
	ret

However BEXT is supposed to replace an SLL operation so adjust the test
case to reject SLL rather than AND, letting the test case pass even with
`/-mmovcc/-mbranch-cost=7' specified as DejaGNU test flags (and in the
absence of target-specific conditional-move operations enabled either by
default or with other test flags).

	gcc/
	* config/riscv/predicates.md (movcc_operand): New predicate.
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Handle
	generic targets.
	* config/riscv/riscv.md (mov<mode>cc): Likewise.
	* config/riscv/riscv.opt (mmovcc): New option.
	* doc/invoke.texi (Option Summary): Document it.

	gcc/testsuite/
	* gcc.target/riscv/zbs-bext-02.c: Adjust to reject SLL rather
	than AND.
2023-11-22 01:18:28 +00:00
Maciej W. Rozycki
4daeedcbaf RISC-V: Implement `riscv_emit_unary' helper
Add a `riscv_emit_unary' helper for unary operations, complementing
`riscv_emit_binary'.

	gcc/
	* config/riscv/riscv-protos.h (riscv_emit_unary): New prototype.
	* config/riscv/riscv.cc (riscv_emit_unary): New function.
2023-11-22 01:18:28 +00:00
Maciej W. Rozycki
6e32373214 RISC-V/testsuite: Add branchless cases for T-Head non-equality cond moves
Verify, for T-Head targets and the non-equality integer conditional-move
operations, that if-conversion triggers via `noce_try_cmove' at
`-mbranch-cost=2' setting, which makes branchless code sequences
produced by if-conversion cheaper than their original branched
equivalents, and that extraneous instructions such as SNEZ, etc. are not
present in output.

	gcc/testsuite/
	* gcc.target/riscv/movdige-thead.c: New test.
	* gcc.target/riscv/movdigeu-thead.c: New test.
	* gcc.target/riscv/movdigt-thead.c: New test.
	* gcc.target/riscv/movdigtu-thead.c: New test.
	* gcc.target/riscv/movdile-thead.c: New test.
	* gcc.target/riscv/movdileu-thead.c: New test.
	* gcc.target/riscv/movdilt-thead.c: New test.
	* gcc.target/riscv/movdiltu-thead.c: New test.
	* gcc.target/riscv/movsige-thead.c: New test.
	* gcc.target/riscv/movsigeu-thead.c: New test.
	* gcc.target/riscv/movsigt-thead.c: New test.
	* gcc.target/riscv/movsigtu-thead.c: New test.
	* gcc.target/riscv/movsile-thead.c: New test.
	* gcc.target/riscv/movsileu-thead.c: New test.
	* gcc.target/riscv/movsilt-thead.c: New test.
	* gcc.target/riscv/movsiltu-thead.c: New test.
2023-11-22 01:18:27 +00:00
Maciej W. Rozycki
4f83f79d93 RISC-V/testsuite: Add branched cases for T-Head non-equality cond moves
Verify, for T-Head targets and the non-equality integer conditional-move
operations, that if-conversion does *not* trigger at `-mbranch-cost=1'
setting, which makes original branched code sequences cheaper than their
branchless equivalents if-conversion would emit.

	gcc/testsuite/
	* gcc.target/riscv/movdibge-thead.c: New test.
	* gcc.target/riscv/movdibgeu-thead.c: New test.
	* gcc.target/riscv/movdibgt-thead.c: New test.
	* gcc.target/riscv/movdibgtu-thead.c: New test.
	* gcc.target/riscv/movdible-thead.c: New test.
	* gcc.target/riscv/movdibleu-thead.c: New test.
	* gcc.target/riscv/movdiblt-thead.c: New test.
	* gcc.target/riscv/movdibltu-thead.c: New test.
	* gcc.target/riscv/movsibge-thead.c: New test.
	* gcc.target/riscv/movsibgeu-thead.c: New test.
	* gcc.target/riscv/movsibgt-thead.c: New test.
	* gcc.target/riscv/movsibgtu-thead.c: New test.
	* gcc.target/riscv/movsible-thead.c: New test.
	* gcc.target/riscv/movsibleu-thead.c: New test.
	* gcc.target/riscv/movsiblt-thead.c: New test.
	* gcc.target/riscv/movsibltu-thead.c: New test.
2023-11-22 01:18:27 +00:00
Maciej W. Rozycki
413ebfd660 RISC-V: Fold all the cond-move variants together
Code in `riscv_expand_conditional_move' for Ventana and Zicond targets
seems like bolted on as an afterthought rather than properly merged so
as to handle all the cases together.

Fold the existing code pieces together then (observing that for short
forward branch targets no integer comparisons need to be canonicalized),
letting T-Head targets produce branchless sequences for all the integer
comparisons rather than for equality ones only, and preparing for the
handling of floating-point comparisons here across all conditional-move
targets.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Unify
	conditional-move handling across all the relevant targets.
2023-11-22 01:18:27 +00:00
Maciej W. Rozycki
566a2b3baa RISC-V: Also accept constants for T-Head cond-move data input operands
There is no need for the requirement for conditional-move data input
operands to be stricter for T-Head targets than for short forward branch
targets and limit them to registers only.  They are keyed according to
the `sfb_alu_operand' predicate, which lets certain constants through.
Such constants are already forced into a register for the `cons' operand
in the analogous short forward branch case and we can force them for the
`alt' operand and T-Head as well.  This enables more opportunities for a
branchless sequence to be produced.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Also
	accept constants for T-Head data input operands.
2023-11-22 01:18:27 +00:00
Maciej W. Rozycki
eeb112542f RISC-V: Also accept constants for T-Head cond-move comparison operands
There is no need for the requirement for conditional-move comparison
operands to be stricter for T-Head targets than for other targets and
limit them to registers only.  Constants will be reloaded if required
just as with branches or other-target conditional-move operations and
there is no extra overhead specific to the T-Head case.  This enables
more opportunities for a branchless sequence to be produced.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Also
	accept constants for T-Head comparison operands.
2023-11-22 01:18:27 +00:00
Maciej W. Rozycki
c47fb7d09e RISC-V/testsuite: Add branchless cases for equality cond-move operations
Verify, for Ventana and Zicond targets and the equality conditional-move
operations, that if-conversion triggers via `noce_try_cmove' at the
respective sufficiently high `-mbranch-cost=' settings that make
branchless code sequences produced by if-conversion cheaper than their
original branched equivalents, and that extraneous instructions such as
SNEZ, etc. are not present in output.

	gcc/testsuite/
	* gcc.target/riscv/movdieq-ventana.c: New test.
	* gcc.target/riscv/movdieq-zicond.c: New test.
	* gcc.target/riscv/movdine-ventana.c: New test.
	* gcc.target/riscv/movdine-zicond.c: New test.
	* gcc.target/riscv/movsieq-ventana.c: New test.
	* gcc.target/riscv/movsieq-zicond.c: New test.
	* gcc.target/riscv/movsine-ventana.c: New test.
	* gcc.target/riscv/movsine-zicond.c: New test.
2023-11-22 01:18:26 +00:00
Maciej W. Rozycki
5e884a8942 RISC-V/testsuite: Add branched cases for equality cond-move operations
Verify, for Ventana and Zicond targets and the equality conditional-move
operations, that if-conversion does *not* trigger at the respective
sufficiently low `-mbranch-cost=' settings that make original branched
code sequences cheaper than their branchless equivalents if-conversion
would emit.

	gcc/testsuite/
	* gcc.target/riscv/movdibeq-ventana.c: New test.
	* gcc.target/riscv/movdibeq-zicond.c: New test.
	* gcc.target/riscv/movdibne-ventana.c: New test.
	* gcc.target/riscv/movdibne-zicond.c: New test.
	* gcc.target/riscv/movsibeq-ventana.c: New test.
	* gcc.target/riscv/movsibeq-zicond.c: New test.
	* gcc.target/riscv/movsibne-ventana.c: New test.
	* gcc.target/riscv/movsibne-zicond.c: New test.
2023-11-22 01:18:26 +00:00
Maciej W. Rozycki
cfec7fc110 RISC-V: Avoid extraneous EQ or NE operation in cond-move expansion
In the non-zero case there is no need for the conditional value used by
Ventana and Zicond integer conditional operations to be specifically 1.
Regardless we canonicalize it by producing an extraneous conditional-set
operation, such as with the sequence below:

(insn 22 6 23 2 (set (reg:DI 141)
        (minus:DI (reg/v:DI 135 [ w ])
            (reg/v:DI 136 [ x ]))) 11 {subdi3}
     (nil))
(insn 23 22 24 2 (set (reg:DI 140)
        (ne:DI (reg:DI 141)
            (const_int 0 [0]))) 307 {*sne_zero_didi}
     (nil))
(insn 24 23 25 2 (set (reg:DI 143)
        (if_then_else:DI (eq:DI (reg:DI 140)
                (const_int 0 [0]))
            (const_int 0 [0])
            (reg:DI 13 a3 [ z ]))) 27913 {*czero.eqz.didi}
     (nil))
(insn 25 24 26 2 (set (reg:DI 142)
        (if_then_else:DI (ne:DI (reg:DI 140)
                (const_int 0 [0]))
            (const_int 0 [0])
            (reg/v:DI 137 [ y ]))) 27914 {*czero.nez.didi}
     (nil))
(insn 26 25 18 2 (set (reg/v:DI 138 [ z ])
        (ior:DI (reg:DI 142)
            (reg:DI 143))) 105 {iordi3}
     (nil))

where insn 23 can well be removed without changing the semantics of the
sequence.  This is actually fixed up later on by combine and the insn
does not make it to output meaning no SNEZ (or SEQZ in the reverse case)
appears in the assembly produced, however it counts towards the cost of
the sequence calculated by if-conversion, raising the trigger level for
the branchless sequence to be chosen.  Arguably to emit this extraneous
operation it can be also considered rather sloppy of our backend's.

Remove the check for operand 1 being constant 0 in the Ventana/Zicond
case for equality comparisons then, observing that `riscv_zero_if_equal'
called via `riscv_emit_int_compare' will canonicalize the comparison if
required, removing the extraneous insn from output:

(insn 22 6 23 2 (set (reg:DI 142)
        (minus:DI (reg/v:DI 135 [ w ])
            (reg/v:DI 136 [ x ]))) 11 {subdi3}
     (nil))
(insn 23 22 24 2 (set (reg:DI 141)
        (if_then_else:DI (eq:DI (reg:DI 142)
                (const_int 0 [0]))
            (const_int 0 [0])
            (reg:DI 13 a3 [ z ]))) 27913 {*czero.eqz.didi}
     (nil))
(insn 24 23 25 2 (set (reg:DI 140)
        (if_then_else:DI (ne:DI (reg:DI 142)
                (const_int 0 [0]))
            (const_int 0 [0])
            (reg/v:DI 137 [ y ]))) 27914 {*czero.nez.didi}
     (nil))
(insn 25 24 18 2 (set (reg/v:DI 138 [ z ])
        (ior:DI (reg:DI 140)
            (reg:DI 141))) 105 {iordi3}
     (nil))

while keeping actual assembly produced the same.

Adjust branch costs across the test cases affected accordingly.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Remove
	the check for operand 1 being constant 0 in the Ventana/Zicond
	case for equality comparisons.

	gcc/testsuite/
	* gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_imm_imm.c:
	Lower `-mbranch-cost=' setting.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_imm_reg.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_reg_reg.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_imm_imm.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_imm_reg.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_reg_reg.c:
	Likewise.
2023-11-22 01:18:26 +00:00
Maciej W. Rozycki
3a746501f6 RISC-V/testsuite: Add branchless cases for GEU and LEU cond-move operations
Verify, for Ventana and Zicond targets and the GEU and LEU
conditional-move operations, that if-conversion triggers via
`noce_try_cmove' at `-mbranch-cost=4' setting, which makes branchless
code sequences produced by if-conversion cheaper than their original
branched equivalents, and that extraneous instructions such as SEQZ,
etc. are not present in output.

	gcc/testsuite/
	* gcc.target/riscv/movdigtu-ventana.c: New test.
	* gcc.target/riscv/movdigtu-zicond.c: New test.
	* gcc.target/riscv/movdiltu-ventana.c: New test.
	* gcc.target/riscv/movdiltu-zicond.c: New test.
	* gcc.target/riscv/movsigtu-ventana.c: New test.
	* gcc.target/riscv/movsigtu-zicond.c: New test.
	* gcc.target/riscv/movsiltu-ventana.c: New test.
	* gcc.target/riscv/movsiltu-zicond.c: New test.
2023-11-22 01:18:26 +00:00
Maciej W. Rozycki
cfa6536f29 RISC-V/testsuite: Add branched cases for GEU and LEU cond-move operations
Verify, for Ventana and Zicond targets and the GEU and LEU
conditional-move operations, that if-conversion does *not* trigger at
`-mbranch-cost=3' setting, which makes original branched code sequences
cheaper than their branchless equivalents if-conversion would emit.

	gcc/testsuite/
	* gcc.target/riscv/movdibgtu-ventana.c: New test.
	* gcc.target/riscv/movdibgtu-zicond.c: New test.
	* gcc.target/riscv/movdibltu-ventana.c: New test.
	* gcc.target/riscv/movdibltu-zicond.c: New test.
	* gcc.target/riscv/movsibgtu-ventana.c: New test.
	* gcc.target/riscv/movsibgtu-zicond.c: New test.
	* gcc.target/riscv/movsibltu-ventana.c: New test.
	* gcc.target/riscv/movsibltu-zicond.c: New test.
2023-11-22 01:18:26 +00:00
Maciej W. Rozycki
db9d825b21 RISC-V: Also invert the cond-move condition for GEU and LEU
Update `riscv_expand_conditional_move' and handle the missing GEU and
LEU operators there, avoiding an extraneous conditional set operation,
such as with this output:

	sgtu	a0,a0,a1
	seqz	a1,a0
	czero.eqz	a3,a3,a1
	czero.nez	a1,a2,a1
	or	a0,a1,a3

produced when optimizing for Zicond targets from:

int
movsigtu (int w, int x, int y, int z)
{
  return w > x ? y : z;
}

These operators can be inverted producing optimal code such as this:

	sgtu	a1,a0,a1
	czero.nez	a3,a3,a1
	czero.eqz	a1,a2,a1
	or	a0,a1,a3

which this change causes to happen.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Also
	invert the condition for GEU and LEU.
2023-11-22 01:18:25 +00:00
Maciej W. Rozycki
814485b256 RISC-V/testsuite: Add branchless cases for FP cond-move operations
Verify, for short forward branch, T-Head, Ventana and Zicond targets and
the ordered floating-point conditional-move operations that already work
as expected, that if-conversion triggers via `noce_try_cmove' at the
respective sufficiently high `-mbranch-cost=' settings that make
branchless code sequences produced by if-conversion cheaper than their
original branched equivalents, and that extraneous instructions such as
SNEZ, etc. are not present in output.  Cover all ordered floating-point
relational operations to make sure no corner case escapes.

	gcc/testsuite/
	* gcc.target/riscv/movdifge-sfb.c: New test.
	* gcc.target/riscv/movdifge-thead.c: New test.
	* gcc.target/riscv/movdifge-ventana.c: New test.
	* gcc.target/riscv/movdifge-zicond.c: New test.
	* gcc.target/riscv/movdifgt-sfb.c: New test.
	* gcc.target/riscv/movdifgt-thead.c: New test.
	* gcc.target/riscv/movdifgt-ventana.c: New test.
	* gcc.target/riscv/movdifgt-zicond.c: New test.
	* gcc.target/riscv/movdifle-sfb.c: New test.
	* gcc.target/riscv/movdifle-thead.c: New test.
	* gcc.target/riscv/movdifle-ventana.c: New test.
	* gcc.target/riscv/movdifle-zicond.c: New test.
	* gcc.target/riscv/movdiflt-sfb.c: New test.
	* gcc.target/riscv/movdiflt-thead.c: New test.
	* gcc.target/riscv/movdiflt-ventana.c: New test.
	* gcc.target/riscv/movdiflt-zicond.c: New test.
	* gcc.target/riscv/movdifne-sfb.c: New test.
	* gcc.target/riscv/movdifne-thead.c: New test.
	* gcc.target/riscv/movdifne-ventana.c: New test.
	* gcc.target/riscv/movdifne-zicond.c: New test.
	* gcc.target/riscv/movsifge-sfb.c: New test.
	* gcc.target/riscv/movsifge-thead.c: New test.
	* gcc.target/riscv/movsifge-ventana.c: New test.
	* gcc.target/riscv/movsifge-zicond.c: New test.
	* gcc.target/riscv/movsifgt-sfb.c: New test.
	* gcc.target/riscv/movsifgt-thead.c: New test.
	* gcc.target/riscv/movsifgt-ventana.c: New test.
	* gcc.target/riscv/movsifgt-zicond.c: New test.
	* gcc.target/riscv/movsifle-sfb.c: New test.
	* gcc.target/riscv/movsifle-thead.c: New test.
	* gcc.target/riscv/movsifle-ventana.c: New test.
	* gcc.target/riscv/movsifle-zicond.c: New test.
	* gcc.target/riscv/movsiflt-sfb.c: New test.
	* gcc.target/riscv/movsiflt-thead.c: New test.
	* gcc.target/riscv/movsiflt-ventana.c: New test.
	* gcc.target/riscv/movsiflt-zicond.c: New test.
	* gcc.target/riscv/movsifne-sfb.c: New test.
	* gcc.target/riscv/movsifne-thead.c: New test.
	* gcc.target/riscv/movsifne-ventana.c: New test.
	* gcc.target/riscv/movsifne-zicond.c: New test.
2023-11-22 01:18:25 +00:00
Maciej W. Rozycki
bc40013cd6 RISC-V/testsuite: Add branched cases for FP cond-move operations
Verify, for Ventana and Zicond targets and the ordered floating-point
conditional-move operations that already work as expected, that
if-conversion does *not* trigger at `-mbranch-cost=2' setting, which
makes original branched code sequences cheaper than their branchless
equivalents if-conversion would emit.  Cover all ordered floating-point
relational operations to make sure no corner case escapes.

	gcc/testsuite/
	* gcc.target/riscv/movdibfge-ventana.c: New test.
	* gcc.target/riscv/movdibfge-zicond.c: New test.
	* gcc.target/riscv/movdibfgt-ventana.c: New test.
	* gcc.target/riscv/movdibfgt-zicond.c: New test.
	* gcc.target/riscv/movdibfle-ventana.c: New test.
	* gcc.target/riscv/movdibfle-zicond.c: New test.
	* gcc.target/riscv/movdibflt-ventana.c: New test.
	* gcc.target/riscv/movdibflt-zicond.c: New test.
	* gcc.target/riscv/movdibfne-ventana.c: New test.
	* gcc.target/riscv/movdibfne-zicond.c: New test.
	* gcc.target/riscv/movsibfge-ventana.c: New test.
	* gcc.target/riscv/movsibfge-zicond.c: New test.
	* gcc.target/riscv/movsibfgt-ventana.c: New test.
	* gcc.target/riscv/movsibfgt-zicond.c: New test.
	* gcc.target/riscv/movsibfle-ventana.c: New test.
	* gcc.target/riscv/movsibfle-zicond.c: New test.
	* gcc.target/riscv/movsibflt-ventana.c: New test.
	* gcc.target/riscv/movsibflt-zicond.c: New test.
	* gcc.target/riscv/movsibfne-ventana.c: New test.
	* gcc.target/riscv/movsibfne-zicond.c: New test.
2023-11-22 01:18:25 +00:00
Maciej W. Rozycki
28d6d6bfbd RISC-V/testsuite: Add branchless cases for integer cond-move operations
Verify, for T-Head, Ventana and Zicond targets and the integer
conditional-move operations that already work as expected, if-conversion
to trigger via `noce_try_cmove' at the respective sufficiently high
`-mbranch-cost=' settings that make branchless code sequences produced
by if-conversion cheaper than their original branched equivalents, and
that extraneous instructions such as SNEZ, etc. are not present in
output.  Cover all integer relational operations to make sure no corner
case escapes.

	gcc/testsuite/
	* gcc.target/riscv/movdieq-thead.c: New test.
	* gcc.target/riscv/movdige-ventana.c: New test.
	* gcc.target/riscv/movdige-zicond.c: New test.
	* gcc.target/riscv/movdigeu-ventana.c: New test.
	* gcc.target/riscv/movdigeu-zicond.c: New test.
	* gcc.target/riscv/movdigt-ventana.c: New test.
	* gcc.target/riscv/movdigt-zicond.c: New test.
	* gcc.target/riscv/movdile-ventana.c: New test.
	* gcc.target/riscv/movdile-zicond.c: New test.
	* gcc.target/riscv/movdileu-ventana.c: New test.
	* gcc.target/riscv/movdileu-zicond.c: New test.
	* gcc.target/riscv/movdilt-ventana.c: New test.
	* gcc.target/riscv/movdilt-zicond.c: New test.
	* gcc.target/riscv/movdine-thead.c: New test.
	* gcc.target/riscv/movsieq-thead.c: New test.
	* gcc.target/riscv/movsige-ventana.c: New test.
	* gcc.target/riscv/movsige-zicond.c: New test.
	* gcc.target/riscv/movsigeu-ventana.c: New test.
	* gcc.target/riscv/movsigeu-zicond.c: New test.
	* gcc.target/riscv/movsigt-ventana.c: New test.
	* gcc.target/riscv/movsigt-zicond.c: New test.
	* gcc.target/riscv/movsile-ventana.c: New test.
	* gcc.target/riscv/movsile-zicond.c: New test.
	* gcc.target/riscv/movsileu-ventana.c: New test.
	* gcc.target/riscv/movsileu-zicond.c: New test.
	* gcc.target/riscv/movsilt-ventana.c: New test.
	* gcc.target/riscv/movsilt-zicond.c: New test.
	* gcc.target/riscv/movsine-thead.c: New test.
2023-11-22 01:18:25 +00:00
Maciej W. Rozycki
dcf4395fc6 RISC-V/testsuite: Add branched cases for integer cond-move operations
Verify, for T-Head, Ventana and Zicond targets and the integer
conditional-move operations that already work as expected, that
if-conversion does *not* trigger at the respective sufficiently low
`-mbranch-cost=' settings that make original branched code sequences
cheaper than their branchless equivalents if-conversion would emit.
Cover all integer relational operations to make sure no corner case
escapes.

The reason to XFAIL movdibne-thead.c and movsibne-thead.c is the
branchless T-Head sequence:

	sub	a1,a0,a1
	th.mveqz	a2,a3,a1
	mv	a0,a2
	ret

produced rather than its original branched counterpart:

	beq	a0,a1,.L3
	mv	a0,a2
	ret
.L3:
	mv	a0,a3
	ret

at `-mbranch-cost=1', even though under this setting the latter sequence
is obviously cheaper performance-wise.  This is because the final move
instruction in the branchless sequence is not counted towards its cost
and consequently the cost of both sequences works out at 8 each, making
if-conversion prefer the branchless variant.  Use the XFAIL mark to keep
track of these cases for future consideration.

	gcc/testsuite/
	* gcc.target/riscv/movdibeq-thead.c: New test.
	* gcc.target/riscv/movdibge-ventana.c: New test.
	* gcc.target/riscv/movdibge-zicond.c: New test.
	* gcc.target/riscv/movdibgeu-ventana.c: New test.
	* gcc.target/riscv/movdibgeu-zicond.c: New test.
	* gcc.target/riscv/movdibgt-ventana.c: New test.
	* gcc.target/riscv/movdibgt-zicond.c: New test.
	* gcc.target/riscv/movdible-ventana.c: New test.
	* gcc.target/riscv/movdible-zicond.c: New test.
	* gcc.target/riscv/movdibleu-ventana.c: New test.
	* gcc.target/riscv/movdibleu-zicond.c: New test.
	* gcc.target/riscv/movdiblt-ventana.c: New test.
	* gcc.target/riscv/movdiblt-zicond.c: New test.
	* gcc.target/riscv/movdibne-thead.c: New test.
	* gcc.target/riscv/movsibeq-thead.c: New test.
	* gcc.target/riscv/movsibge-ventana.c: New test.
	* gcc.target/riscv/movsibge-zicond.c: New test.
	* gcc.target/riscv/movsibgeu-ventana.c: New test.
	* gcc.target/riscv/movsibgeu-zicond.c: New test.
	* gcc.target/riscv/movsibgt-ventana.c: New test.
	* gcc.target/riscv/movsibgt-zicond.c: New test.
	* gcc.target/riscv/movsible-ventana.c: New test.
	* gcc.target/riscv/movsible-zicond.c: New test.
	* gcc.target/riscv/movsibleu-ventana.c: New test.
	* gcc.target/riscv/movsibleu-zicond.c: New test.
	* gcc.target/riscv/movsiblt-ventana.c: New test.
	* gcc.target/riscv/movsiblt-zicond.c: New test.
	* gcc.target/riscv/movsibne-thead.c: New test.
2023-11-22 01:18:25 +00:00
Maciej W. Rozycki
c1e8cb3d9f RISC-V: Rework branch costing model for if-conversion
The generic branch costing model for if-conversion assumes a fixed cost
of COSTS_N_INSNS (2) for a conditional branch, and that one half of that
cost comes from a preceding condition-set instruction, such as with
MODE_CC targets, and then the other half of that cost is for the actual
branch instruction.  This is hardcoded for `if_info.original_cost' in
`noce_find_if_block' and regardless of the cost set for branches via
BRANCH_COST.

Then `default_max_noce_ifcvt_seq_cost' instructs if-conversion to prefer
a branchless sequence as costly as high as triple the BRANCH_COST value
set.  This is apparently to make up for the inability to accurately
guess the branch penalty.

Consequently for the BRANCH_COST of 3 we commonly set for tuning,
if-conversion will consider branchless sequences costing 3 * 3 - 2 = 7
instruction units more than a corresponding branch sequence.  For the
BRANCH_COST of 4 such as with `sifive-7-series' tuning this is even
worse, at 3 * 4 - 2 = 10.  Effectively it means a branchless sequence
will always be chosen if available, even a very inefficient one.

Rework the branch costing model to better match our architecture,
observing in particular that we have no preparatory instructions for
branches so that the cost of a branch is naked BRANCH_COST plus any
extra overhead the processing of a branch's source RTX might incur.

Provide TARGET_INSN_COST and TARGET_MAX_NOCE_IFCVT_SEQ_COST handlers
than that return suitable cost based on BRANCH_COST.  The latter hook
usually returns a value that is lower than the cost of the corresponding
branched sequence.  This is because we don't really want to produce a
branchless sequence that is more expensive than the original branched
sequence.  If this turns out too conservative for some corner case, then
this choice might be revisited.

Then we don't want to fiddle with `noce_find_if_block' without a lot of
cross-target verification, so add TARGET_NOCE_CONVERSION_PROFITABLE_P
defined such that it subtracts the fixed COSTS_N_INSNS (2) cost from the
cost of the original branched sequence supplied and instead adds actual
branch cost calculated from the conditional branch instruction used.  It
is then further tweaked according to simple analysis of the replacement
branchless sequence produced so as to cancel the cost of an extraneous
zero extend operation produced by `noce_try_store_flag_mask' as observed
with gcc/testsuite/gcc.target/riscv/pr105314.c.

Tweak the testsuite accordingly and set `-mbranch-cost=' explicitly for
the relevant cases so that the expected if-conversion transformation is
made regardless of the default BRANCH_COST value of tuning in effect.
Some of these settings will be lowered later on as deficiencies in
branchless sequence generation have been fixed that lower their cost
calculated by if-conversion.

	gcc/
	* config/riscv/riscv.cc (riscv_insn_cost): New function.
	(riscv_max_noce_ifcvt_seq_cost): Likewise.
	(riscv_noce_conversion_profitable_p): Likewise.
	(TARGET_INSN_COST): New macro.
	(TARGET_MAX_NOCE_IFCVT_SEQ_COST): New macro.
	(TARGET_NOCE_CONVERSION_PROFITABLE_P): New macro.

	gcc/testsuite/
	* gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_imm_imm.c:
	Explicitly set the branch cost.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_imm_reg.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_reg_reg.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_imm_imm.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_imm_reg.c:
	Likewise.
	* gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_reg_reg.c:
	Likewise.
2023-11-22 01:18:25 +00:00
Maciej W. Rozycki
35bea66d36 RISC-V: Simplify EQ vs NE selection in `riscv_expand_conditional_move'
Just choose between EQ and NE at `gen_rtx_fmt_ee' invocation, removing
an extraneous variable only referred once and improving code clarity.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Remove
	extraneous variable for EQ vs NE operation selection.
2023-11-22 01:18:24 +00:00
Maciej W. Rozycki
5a21d50756 RISC-V: Use nullptr' in riscv_expand_conditional_move'
Use `nullptr' for consistency rather than 0 to initialize `invert_ptr'.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
	`nullptr' rather than 0 to initialize a pointer.
2023-11-22 01:18:24 +00:00
Maciej W. Rozycki
00a3bd4cca RISC-V: Avoid repeated GET_MODE calls in `riscv_expand_conditional_move'
Use `mode0' and `mode1' shorthands respectively for `GET_MODE (op0)' and
`GET_MODE (op1)' to improve code readability.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
	`mode0' and `mode1' for `GET_MODE (op0)' and `GET_MODE (op1)'.
2023-11-22 01:18:24 +00:00
Maciej W. Rozycki
04c9c27c6f RISC-V: Fix mode' usage in riscv_expand_conditional_move'
In `riscv_expand_conditional_move' `mode' is initialized right away from
`GET_MODE (dest)', so remove needless references that refrain from using
the local variable.

	gcc/
	* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
	`mode' for `GET_MODE (dest)' throughout.
2023-11-22 01:18:24 +00:00
Maciej W. Rozycki
9f5aa4e210 RISC-V: Sanitise NEED_EQ_NE_P case with `riscv_emit_int_compare'
For the NEED_EQ_NE_P `riscv_emit_int_compare' is documented to only emit
EQ or NE comparisons against zero, however it does not catch incorrect
use where a non-equality comparison has been requested and falls through
to the general case then.  Add a safety guard to catch such a case then.

Arguably the NEED_EQ_NE_P case would best be moved into a function of
its own, but let's leave it for a separate cleanup.

	gcc/
	* config/riscv/riscv.cc (riscv_emit_int_compare): Bail out if
	NEED_EQ_NE_P but the comparison is neither EQ nor NE.
2023-11-22 01:18:23 +00:00
Maciej W. Rozycki
3bb4000c5f RISC-V: Reorder comment on SFB patterns
Our `mov<mode>cc' expander is no longer specific to short forward branch
targets, so move its associated comment accordingly.

	gcc/
	* config/riscv/riscv.md (mov<mode>cc): Move comment on SFB
	patterns over to...
	(*mov<GPR:mode><X:mode>cc): ... here.
2023-11-22 01:18:23 +00:00
Maciej W. Rozycki
932fe50a8b RISC-V/testsuite: Add cases for integer SFB cond-move operations
Verify, for short forward branch targets and the conditional-move
operations that already work as expected, that if-conversion triggers
via `noce_try_cmove' already at `-mbranch-cost=1' and that extraneous
instructions such as SNEZ, etc. are not present in output.  Cover all
integer relational operations to make sure no corner case escapes.

	gcc/testsuite/
	* gcc.target/riscv/movdieq-sfb.c: New test.
	* gcc.target/riscv/movdige-sfb.c: New test.
	* gcc.target/riscv/movdigeu-sfb.c: New test.
	* gcc.target/riscv/movdigt-sfb.c: New test.
	* gcc.target/riscv/movdigtu-sfb.c: New test.
	* gcc.target/riscv/movdile-sfb.c: New test.
	* gcc.target/riscv/movdileu-sfb.c: New test.
	* gcc.target/riscv/movdilt-sfb.c: New test.
	* gcc.target/riscv/movdiltu-sfb.c: New test.
	* gcc.target/riscv/movdine-sfb.c: New test.
	* gcc.target/riscv/movsieq-sfb.c: New test.
	* gcc.target/riscv/movsige-sfb.c: New test.
	* gcc.target/riscv/movsigeu-sfb.c: New test.
	* gcc.target/riscv/movsigt-sfb.c: New test.
	* gcc.target/riscv/movsigtu-sfb.c: New test.
	* gcc.target/riscv/movsile-sfb.c: New test.
	* gcc.target/riscv/movsileu-sfb.c: New test.
	* gcc.target/riscv/movsilt-sfb.c: New test.
	* gcc.target/riscv/movsiltu-sfb.c: New test.
	* gcc.target/riscv/movsine-sfb.c: New test.
2023-11-22 01:18:23 +00:00
Maciej W. Rozycki
c21ad4bee5 testsuite: Add cases for conditional-move and conditional-add operations
Add generic execution tests for expressions that are expected to expand
to conditional-move and conditional-add operations where supported.  To
ensure no corner case escapes all relational operators are extensively
covered for integer comparisons and all ordered operators are covered
for floating-point comparisons.  Unordered operators are not covered at
this point as they'd require a different input data set.

	gcc/testsuite/
	* gcc.dg/torture/addieq.c: New test.
	* gcc.dg/torture/addifeq.c: New test.
	* gcc.dg/torture/addifge.c: New test.
	* gcc.dg/torture/addifgt.c: New test.
	* gcc.dg/torture/addifle.c: New test.
	* gcc.dg/torture/addiflt.c: New test.
	* gcc.dg/torture/addifne.c: New test.
	* gcc.dg/torture/addige.c: New test.
	* gcc.dg/torture/addigeu.c: New test.
	* gcc.dg/torture/addigt.c: New test.
	* gcc.dg/torture/addigtu.c: New test.
	* gcc.dg/torture/addile.c: New test.
	* gcc.dg/torture/addileu.c: New test.
	* gcc.dg/torture/addilt.c: New test.
	* gcc.dg/torture/addiltu.c: New test.
	* gcc.dg/torture/addine.c: New test.
	* gcc.dg/torture/addleq.c: New test.
	* gcc.dg/torture/addlfeq.c: New test.
	* gcc.dg/torture/addlfge.c: New test.
	* gcc.dg/torture/addlfgt.c: New test.
	* gcc.dg/torture/addlfle.c: New test.
	* gcc.dg/torture/addlflt.c: New test.
	* gcc.dg/torture/addlfne.c: New test.
	* gcc.dg/torture/addlge.c: New test.
	* gcc.dg/torture/addlgeu.c: New test.
	* gcc.dg/torture/addlgt.c: New test.
	* gcc.dg/torture/addlgtu.c: New test.
	* gcc.dg/torture/addlle.c: New test.
	* gcc.dg/torture/addlleu.c: New test.
	* gcc.dg/torture/addllt.c: New test.
	* gcc.dg/torture/addlltu.c: New test.
	* gcc.dg/torture/addlne.c: New test.
	* gcc.dg/torture/movieq.c: New test.
	* gcc.dg/torture/movifeq.c: New test.
	* gcc.dg/torture/movifge.c: New test.
	* gcc.dg/torture/movifgt.c: New test.
	* gcc.dg/torture/movifle.c: New test.
	* gcc.dg/torture/moviflt.c: New test.
	* gcc.dg/torture/movifne.c: New test.
	* gcc.dg/torture/movige.c: New test.
	* gcc.dg/torture/movigeu.c: New test.
	* gcc.dg/torture/movigt.c: New test.
	* gcc.dg/torture/movigtu.c: New test.
	* gcc.dg/torture/movile.c: New test.
	* gcc.dg/torture/movileu.c: New test.
	* gcc.dg/torture/movilt.c: New test.
	* gcc.dg/torture/moviltu.c: New test.
	* gcc.dg/torture/movine.c: New test.
	* gcc.dg/torture/movleq.c: New test.
	* gcc.dg/torture/movlfeq.c: New test.
	* gcc.dg/torture/movlfge.c: New test.
	* gcc.dg/torture/movlfgt.c: New test.
	* gcc.dg/torture/movlfle.c: New test.
	* gcc.dg/torture/movlflt.c: New test.
	* gcc.dg/torture/movlfne.c: New test.
	* gcc.dg/torture/movlge.c: New test.
	* gcc.dg/torture/movlgeu.c: New test.
	* gcc.dg/torture/movlgt.c: New test.
	* gcc.dg/torture/movlgtu.c: New test.
	* gcc.dg/torture/movlle.c: New test.
	* gcc.dg/torture/movlleu.c: New test.
	* gcc.dg/torture/movllt.c: New test.
	* gcc.dg/torture/movlltu.c: New test.
	* gcc.dg/torture/movlne.c: New test.
2023-11-22 01:18:23 +00:00
GCC Administrator
92c480a423 Daily bump. 2023-11-22 00:17:52 +00:00
Thomas Schwinge
a0240662b2 Fix 'gcc.dg/tree-ssa/return-value-range-1.c' for 'char' defaulting to 'unsigned'
... added in recent commit 53ba8d6695
"inter-procedural value range propagation", fixed in
commit 878a860cae
"Fix 'gcc.dg/tree-ssa/return-value-range-1.c'".

	gcc/testsuite/
	* gcc.dg/tree-ssa/return-value-range-1.c: Fix.
2023-11-21 22:16:07 +01:00
Robin Dapp
2bbc7f4ef6 vect: Allow reduc_index != 1 for COND_OPs.
In PR112406 Tamar found another problem with COND_OP reductions.
I wrongly assumed that the reduction variable will always remain in
operand 1, just as we create the COND_OP in ifcvt.  But of course,
addition being commutative, we are free to swap operand 1 and 2 and we
end up with e.g.

 _ifc__60 = .COND_ADD (_2, _6, MADPictureC1_lsm.10_25, MADPictureC1_lsm.10_25);

which does not pass the asserts I put in place.

This patch removes this restriction and allows the reduction index to be
2 as well.

gcc/ChangeLog:

	PR middle-end/112406

	* tree-vect-loop.cc (vectorize_fold_left_reduction): Allow
	reduction index != 1.
	(vect_transform_reduction): Handle reduction index != 1.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/pr112406-2.c: New test.
2023-11-21 21:06:13 +01:00
Robin Dapp
638c2f3caf RISC-V: testsuite: Fix popcount test.
Due to Jakub's recent middle-end changes we now vectorize some more
popcount instances.  This patch just adjusts the dump check.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/unop/popcount.c: Adjust check.
	* lib/target-supports.exp: Add riscv_zbb.
2023-11-21 21:06:13 +01:00
Robin Dapp
686056b796 RISC-V: testsuite: Add rv64 requirement for bug-9 and bug-14.
This adds an effective target requirement to compile the tests.  Since
we disabled 64-bit indices on rv32 targets those tests should be
unsupported on rv32.

gcc/testsuite/ChangeLog:

	* g++.target/riscv/rvv/base/bug-14.C: Add
	dg-require-effective-target rv64.
	* g++.target/riscv/rvv/base/bug-9.C: Ditto.
2023-11-21 21:06:13 +01:00
Robin Dapp
4efa929a02 RISC-V: testsuite: Do not set default arch for RVV.
This removes setting of the default arch and abi in the testsuite.  We
should directly use what the target provides.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/rvv.exp:  Remove -march and -mabi from
	default CFLAGS.
2023-11-21 21:06:13 +01:00
Jakub Jelinek
c7c1ee1cfd sanitizer: Fix build on SPARC/Solaris with Solaris as [PR112562]
Solaris as apparently doesn't accept %function and requires @function
instead.

This cherry-picks upstream commit.

2023-11-21  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/112562
	* sanitizer_common/sanitizer_asm.h: Cherry-pick llvm-project revision
	a855a16a02e76a0f4192c038bb64f3773947a2f7.
	* interception/interception.h: Likewise.
2023-11-21 21:01:48 +01:00
Patrick O'Neill
f1b2f3a7e0
gfortran: Rely on dg-do-what-default to avoid running pr85853.f90, pr107254.f90 and vect-alias-check-1.F90 on non-vector targets
Testcases in gfortran.dg/vect/vect.exp rely on
check_vect_support_and_set_flags to set dg-do-what-default and avoid
running vector tests on non-vector targets. The three testcases in this
patch overwrite the default with dg-do run which causes issues
for non-vector targets.

Removing the dg-do run directive resolves this issue for non-vector
targets (while still running the tests on vector targets).

gcc/testsuite/ChangeLog:

	* gfortran.dg/vect/pr107254.f90: Remove dg-do run directive.
	* gfortran.dg/vect/pr85853.f90: Ditto.
	* gfortran.dg/vect/vect-alias-check-1.F90: Ditto.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
2023-11-21 10:02:23 -08:00
Jonathan Wakely
7adb7c6ea4 libstdc++: Do not declare strtok for C++26 freestanding (P2937R0)
This was recently approved for C++26.

We should define the __cpp_lib_freestanding_cstring macro in <string.h>
as well as <cstring>, but we do not currently install our own <string.h>
for most targets.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (freestanding_cstring): Add.
	* include/bits/version.h: Regenerate.
	* include/c_compatibility/string.h (strtok): Do not declare for
	C++26 freestanding.
	* include/c_global/cstring (strtok): Likewise.
	* testsuite/21_strings/headers/cstring/version.cc: New test.
2023-11-21 15:58:21 +00:00
Jonathan Wakely
43626143c9 libstdc++: Add freestanding feature test macros (P2407R5)
This C++26 change makes several classes "partially freestanding", but we
already fully supported them in freestanding mode. All we need to do is
define the new feature test macros and add tests for them.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (freestanding_algorithm)
	(freestanding_array, freestanding_optional)
	(freestanding_string_view, freestanding_variant): Add.
	* include/bits/version.h: Regenerate.
	* include/std/algorithm (__glibcxx_want_freestanding_algorithm):
	Define.
	* include/std/array (__glibcxx_want_freestanding_array):
	Define.
	* include/std/optional (__glibcxx_want_freestanding_optional):
	Define.
	* include/std/string_view
	(__glibcxx_want_freestanding_string_view): Define.
	* include/std/variant (__glibcxx_want_freestanding_variant):
	Define.
	* testsuite/20_util/optional/version.cc: Add checks for
	__cpp_lib_freestanding_optional.
	* testsuite/20_util/variant/version.cc: Add checks for
	__cpp_lib_freestanding_variant.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error line numbers.
	* testsuite/21_strings/basic_string_view/requirements/version.cc:
	New test.
	* testsuite/23_containers/array/requirements/version.cc: New
	test.
	* testsuite/25_algorithms/fill_n/requirements/version.cc: New
	test.
	* testsuite/25_algorithms/swap_ranges/requirements/version.cc:
	New test.
2023-11-21 15:58:21 +00:00
Jonathan Wakely
1fa85dcf65 libstdc++: Add std::span::at for C++26 (P2821R5)
Also define the new feature test macros from P2833R2, indicating that
std::span and std::expected are supported for freestanding mode.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (freestanding_expected): New macro.
	(span): Add C++26 value.
	* include/bits/version.h: Regenerate.
	* include/std/expected (__glibcxx_want_freestanding_expected):
	Define.
	* include/std/span (span::at): New member function.
	* testsuite/20_util/expected/version.cc: Add checks for
	__cpp_lib_freestanding_expected.
	* testsuite/23_containers/span/2.cc: Moved to...
	* testsuite/23_containers/span/version.cc: ...here. Add checks
	for __cpp_lib_span in <span> as well as in <version>.
	* testsuite/23_containers/span/1.cc: Removed.
	* testsuite/23_containers/span/at.cc: New test.
2023-11-21 15:58:21 +00:00
Jonathan Wakely
49f7620a12 libstdc++: Fix std::tr2::dynamic_bitset support for alternate characters
libstdc++-v3/ChangeLog:

	* include/tr2/dynamic_bitset (dynamic_bitset): Pass zero and one
	characters to _M_copy_from_string.
	* testsuite/tr2/dynamic_bitset/string.cc: New test.
2023-11-21 15:58:21 +00:00
Jonathan Wakely
623b8081ab libstdc++: Remove outdated references to buildstat.html
The buildstat.html pages have not existed since gcc-8 so remove
referencs to them in the libstdc++ manual.

libstdc++-v3/ChangeLog:

	* doc/html/*: Regenerate.
	* doc/xml/faq.xml: Remove reference to buildstat.html pages.
	* doc/xml/manual/test.xml: Likewise
2023-11-21 15:58:20 +00:00
Richard Sandiford
32ce90c601 Add an aligned_register_operand predicate
This patch adds a target-independent aligned_register_operand
predicate, for use with register constraints that use filters
to impose an alignment.  The definition deliberately jetisons
some of the historical baggage in general_operand.

gcc/
	* common.md (aligned_register_operand): New predicate.
2023-11-21 15:39:11 +00:00
Richard Sandiford
ef4e6e2c04 ira: Handle register filters
This patch makes IRA apply register filters when picking hard registers.
All the new code should be optimised away on targets that don't use
register filters.  On targets that do use them, the new register_filters
bitfield is expected to be only a handful of bits.

Information about register filters is recorded in process_bb_node_lives.
The information isn't really related to liveness, but it's a convenient
point because (a) we've already built the allocno structures and
(b) we've already extracted the insn and preprocessed the constraints.

gcc/
	* ira-int.h (ira_allocno): Add a register_filters field.
	(ALLOCNO_REGISTER_FILTERS): New macro.
	(ALLOCNO_SET_REGISTER_FILTERS): Likewise.
	* ira-build.cc (ira_create_allocno): Initialize register_filters.
	(create_cap_allocno): Propagate register_filters.
	(propagate_allocno_info): Likewise.
	(propagate_some_info_from_allocno): Likewise.
	* ira-lives.cc (process_register_constraint_filters): New function.
	(process_bb_node_lives): Use it to record register filter
	information.
	* ira-color.cc (assign_hard_reg): Check register filters.
	(improve_allocation, fast_allocation): Likewise.
2023-11-21 15:39:10 +00:00