Skip to content

Commit 61a5f11

Browse files
committed
8301033: RISC-V: Handle special cases for MinI/MaxI nodes for Zbb
Reviewed-by: fjiang, luhenry, shade
1 parent 82df4a2 commit 61a5f11

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/hotspot/cpu/riscv/riscv_b.ad

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,12 @@ instruct popCountL_b(iRegINoSp dst, iRegL src) %{
395395
%}
396396

397397
// Max and Min
398-
instruct minI_reg_b(iRegINoSp dst, iRegI src1, iRegI src2) %{
398+
instruct minI_reg_reg_b(iRegINoSp dst, iRegI src1, iRegI src2) %{
399399
predicate(UseZbb);
400400
match(Set dst (MinI src1 src2));
401401

402402
ins_cost(ALU_COST);
403-
format %{ "min $dst, $src1, $src2\t#@minI_reg_b" %}
403+
format %{ "min $dst, $src1, $src2\t#@minI_reg_reg_b" %}
404404

405405
ins_encode %{
406406
__ min(as_Register($dst$$reg), as_Register($src1$$reg), as_Register($src2$$reg));
@@ -409,12 +409,12 @@ instruct minI_reg_b(iRegINoSp dst, iRegI src1, iRegI src2) %{
409409
ins_pipe(ialu_reg_reg);
410410
%}
411411

412-
instruct maxI_reg_b(iRegINoSp dst, iRegI src1, iRegI src2) %{
412+
instruct maxI_reg_reg_b(iRegINoSp dst, iRegI src1, iRegI src2) %{
413413
predicate(UseZbb);
414414
match(Set dst (MaxI src1 src2));
415415

416416
ins_cost(ALU_COST);
417-
format %{ "max $dst, $src1, $src2\t#@maxI_reg_b" %}
417+
format %{ "max $dst, $src1, $src2\t#@maxI_reg_reg_b" %}
418418

419419
ins_encode %{
420420
__ max(as_Register($dst$$reg), as_Register($src1$$reg), as_Register($src2$$reg));
@@ -423,6 +423,40 @@ instruct maxI_reg_b(iRegINoSp dst, iRegI src1, iRegI src2) %{
423423
ins_pipe(ialu_reg_reg);
424424
%}
425425

426+
// special case for comparing with zero
427+
// n.b. this is selected in preference to the rule above because it
428+
// avoids loading constant 0 into a source register
429+
430+
instruct minI_reg_zero_b(iRegINoSp dst, iRegI src1, immI0 zero) %{
431+
predicate(UseZbb);
432+
match(Set dst (MinI src1 zero));
433+
match(Set dst (MinI zero src1));
434+
435+
ins_cost(ALU_COST);
436+
format %{ "min $dst, $src1, zr\t#@minI_reg_zero_b" %}
437+
438+
ins_encode %{
439+
__ min(as_Register($dst$$reg), as_Register($src1$$reg), zr);
440+
%}
441+
442+
ins_pipe(ialu_reg_reg);
443+
%}
444+
445+
instruct maxI_reg_zero_b(iRegINoSp dst, iRegI src1, immI0 zero) %{
446+
predicate(UseZbb);
447+
match(Set dst (MaxI src1 zero));
448+
match(Set dst (MaxI zero src1));
449+
450+
ins_cost(ALU_COST);
451+
format %{ "max $dst, $src1, zr\t#@maxI_reg_zero_b" %}
452+
453+
ins_encode %{
454+
__ max(as_Register($dst$$reg), as_Register($src1$$reg), zr);
455+
%}
456+
457+
ins_pipe(ialu_reg_reg);
458+
%}
459+
426460
// Abs
427461
instruct absI_reg_b(iRegINoSp dst, iRegI src) %{
428462
predicate(UseZbb);

0 commit comments

Comments
 (0)