22; RUN: llc -mtriple=riscv64 -global-isel -verify-machineinstrs < %s \
33; RUN: | FileCheck %s -check-prefixes=CHECK,RV64I
44; RUN: llc -mtriple=riscv64 -global-isel -mattr=+zbb -verify-machineinstrs < %s \
5- ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB
5+ ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB,RV64ZBB
66; RUN: llc -mtriple=riscv64 -global-isel -mattr=+zbkb -verify-machineinstrs < %s \
7- ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB
7+ ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB,RV64ZBKB
88
9+ ; FIXME: sext.w is unneeded.
910define signext i32 @andn_i32 (i32 signext %a , i32 signext %b ) nounwind {
1011; RV64I-LABEL: andn_i32:
1112; RV64I: # %bb.0:
@@ -40,6 +41,7 @@ define i64 @andn_i64(i64 %a, i64 %b) nounwind {
4041 ret i64 %and
4142}
4243
44+ ; FIXME: sext.w is unneeded.
4345define signext i32 @orn_i32 (i32 signext %a , i32 signext %b ) nounwind {
4446; RV64I-LABEL: orn_i32:
4547; RV64I: # %bb.0:
@@ -74,6 +76,7 @@ define i64 @orn_i64(i64 %a, i64 %b) nounwind {
7476 ret i64 %or
7577}
7678
79+ ; FIXME: sext.w is unneeded.
7780define signext i32 @xnor_i32 (i32 signext %a , i32 signext %b ) nounwind {
7881; RV64I-LABEL: xnor_i32:
7982; RV64I: # %bb.0:
@@ -424,6 +427,7 @@ define i64 @rori_i64_fshr(i64 %a) nounwind {
424427 ret i64 %1
425428}
426429
430+ ; FIXME: We should use srli instead of srliw for better compression.
427431define i8 @srli_i8 (i8 %a ) nounwind {
428432; CHECK-LABEL: srli_i8:
429433; CHECK: # %bb.0:
@@ -434,21 +438,33 @@ define i8 @srli_i8(i8 %a) nounwind {
434438 ret i8 %1
435439}
436440
437- ; We could use sext.b+srai, but slli+srai offers more opportunities for
438- ; comppressed instructions .
441+ ; FIXME: We should use slli+srai with Zbb for better compression.
442+ ; FIXME: We should combine back to back sraiw .
439443define i8 @srai_i8 (i8 %a ) nounwind {
440444; RV64I-LABEL: srai_i8:
441445; RV64I: # %bb.0:
442446; RV64I-NEXT: slli a0, a0, 24
443447; RV64I-NEXT: sraiw a0, a0, 24
444448; RV64I-NEXT: sraiw a0, a0, 5
445449; RV64I-NEXT: ret
450+ ;
451+ ; RV64ZBB-LABEL: srai_i8:
452+ ; RV64ZBB: # %bb.0:
453+ ; RV64ZBB-NEXT: sext.b a0, a0
454+ ; RV64ZBB-NEXT: sraiw a0, a0, 5
455+ ; RV64ZBB-NEXT: ret
456+ ;
457+ ; RV64ZBKB-LABEL: srai_i8:
458+ ; RV64ZBKB: # %bb.0:
459+ ; RV64ZBKB-NEXT: slli a0, a0, 24
460+ ; RV64ZBKB-NEXT: sraiw a0, a0, 24
461+ ; RV64ZBKB-NEXT: sraiw a0, a0, 5
462+ ; RV64ZBKB-NEXT: ret
446463 %1 = ashr i8 %a , 5
447464 ret i8 %1
448465}
449466
450- ; We could use zext.h+srli, but slli+srli offers more opportunities for
451- ; comppressed instructions.
467+ ; FIXME: We should use slli+srli.
452468define i16 @srli_i16 (i16 %a ) nounwind {
453469; RV64I-LABEL: srli_i16:
454470; RV64I: # %bb.0:
@@ -457,19 +473,46 @@ define i16 @srli_i16(i16 %a) nounwind {
457473; RV64I-NEXT: and a0, a0, a1
458474; RV64I-NEXT: srliw a0, a0, 6
459475; RV64I-NEXT: ret
476+ ;
477+ ; RV64ZBB-LABEL: srli_i16:
478+ ; RV64ZBB: # %bb.0:
479+ ; RV64ZBB-NEXT: zext.h a0, a0
480+ ; RV64ZBB-NEXT: srliw a0, a0, 6
481+ ; RV64ZBB-NEXT: ret
482+ ;
483+ ; RV64ZBKB-LABEL: srli_i16:
484+ ; RV64ZBKB: # %bb.0:
485+ ; RV64ZBKB-NEXT: lui a1, 16
486+ ; RV64ZBKB-NEXT: addi a1, a1, -1
487+ ; RV64ZBKB-NEXT: and a0, a0, a1
488+ ; RV64ZBKB-NEXT: srliw a0, a0, 6
489+ ; RV64ZBKB-NEXT: ret
460490 %1 = lshr i16 %a , 6
461491 ret i16 %1
462492}
463493
464- ; We could use sext.h+srai, but slli+srai offers more opportunities for
465- ; comppressed instructions .
494+ ; FIXME: We should use slli+srai with Zbb/Zbkb for better compression.
495+ ; FIXME: We should combine back to back sraiw .
466496define i16 @srai_i16 (i16 %a ) nounwind {
467497; RV64I-LABEL: srai_i16:
468498; RV64I: # %bb.0:
469499; RV64I-NEXT: slli a0, a0, 16
470500; RV64I-NEXT: sraiw a0, a0, 16
471501; RV64I-NEXT: sraiw a0, a0, 9
472502; RV64I-NEXT: ret
503+ ;
504+ ; RV64ZBB-LABEL: srai_i16:
505+ ; RV64ZBB: # %bb.0:
506+ ; RV64ZBB-NEXT: sext.h a0, a0
507+ ; RV64ZBB-NEXT: sraiw a0, a0, 9
508+ ; RV64ZBB-NEXT: ret
509+ ;
510+ ; RV64ZBKB-LABEL: srai_i16:
511+ ; RV64ZBKB: # %bb.0:
512+ ; RV64ZBKB-NEXT: slli a0, a0, 16
513+ ; RV64ZBKB-NEXT: sraiw a0, a0, 16
514+ ; RV64ZBKB-NEXT: sraiw a0, a0, 9
515+ ; RV64ZBKB-NEXT: ret
473516 %1 = ashr i16 %a , 9
474517 ret i16 %1
475518}
0 commit comments