Skip to content

Commit aa425eb

Browse files
heihertru
authored andcommitted
[LoongArch] Fix codegen for ISD::ROTR (#100292)
This patch fixes the code generation for IR: sext i32 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i64 (cherry picked from commit e386aac)
1 parent 95ed2d0 commit aa425eb

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,6 @@ def : PatGprGpr<urem, MOD_DU>;
11441144
def : PatGprGpr<loongarch_mod_wu, MOD_WU>;
11451145
def : PatGprGpr<rotr, ROTR_D>;
11461146
def : PatGprGpr<loongarch_rotr_w, ROTR_W>;
1147-
def : PatGprGpr_32<rotr, ROTR_W>;
11481147
def : PatGprImm<rotr, ROTRI_D, uimm6>;
11491148
def : PatGprImm_32<rotr, ROTRI_W, uimm5>;
11501149
def : PatGprImm<loongarch_rotr_w, ROTRI_W, uimm5>;

llvm/test/CodeGen/LoongArch/rotl-rotr.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,42 @@ define i64 @rotr_64_mask_or_128_or_64(i64 %x, i64 %y) nounwind {
504504
ret i64 %f
505505
}
506506

507+
define signext i32 @rotr_64_trunc_32(i64 %x, i64 %y) nounwind {
508+
; LA32-LABEL: rotr_64_trunc_32:
509+
; LA32: # %bb.0:
510+
; LA32-NEXT: srl.w $a3, $a0, $a2
511+
; LA32-NEXT: xori $a4, $a2, 31
512+
; LA32-NEXT: slli.w $a5, $a1, 1
513+
; LA32-NEXT: sll.w $a4, $a5, $a4
514+
; LA32-NEXT: or $a3, $a3, $a4
515+
; LA32-NEXT: addi.w $a4, $a2, -32
516+
; LA32-NEXT: slti $a5, $a4, 0
517+
; LA32-NEXT: maskeqz $a3, $a3, $a5
518+
; LA32-NEXT: srl.w $a1, $a1, $a4
519+
; LA32-NEXT: masknez $a1, $a1, $a5
520+
; LA32-NEXT: or $a1, $a3, $a1
521+
; LA32-NEXT: sub.w $a3, $zero, $a2
522+
; LA32-NEXT: sll.w $a0, $a0, $a3
523+
; LA32-NEXT: ori $a3, $zero, 32
524+
; LA32-NEXT: sub.w $a2, $a3, $a2
525+
; LA32-NEXT: srai.w $a2, $a2, 31
526+
; LA32-NEXT: and $a0, $a2, $a0
527+
; LA32-NEXT: or $a0, $a1, $a0
528+
; LA32-NEXT: ret
529+
;
530+
; LA64-LABEL: rotr_64_trunc_32:
531+
; LA64: # %bb.0:
532+
; LA64-NEXT: rotr.d $a0, $a0, $a1
533+
; LA64-NEXT: addi.w $a0, $a0, 0
534+
; LA64-NEXT: ret
535+
%z = sub i64 64, %y
536+
%b = lshr i64 %x, %y
537+
%c = shl i64 %x, %z
538+
%d = or i64 %b, %c
539+
%e = trunc i64 %d to i32
540+
ret i32 %e
541+
}
542+
507543
define signext i32 @rotri_i32(i32 signext %a) nounwind {
508544
; LA32-LABEL: rotri_i32:
509545
; LA32: # %bb.0:

0 commit comments

Comments
 (0)