Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoongArch] Fix codegen for ISD::ROTR #100292

Merged
merged 1 commit into from
Jul 24, 2024
Merged

[LoongArch] Fix codegen for ISD::ROTR #100292

merged 1 commit into from
Jul 24, 2024

Conversation

heiher
Copy link
Member

@heiher heiher commented Jul 24, 2024

This patch fixes the code generation for IR:

sext i32 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i64

This patch fixes the code generation for IR:

sext i64 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i32
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2024

@llvm/pr-subscribers-backend-loongarch

Author: hev (heiher)

Changes

This patch fixes the code generation for IR:

sext i64 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i32


Full diff: https://github.com/llvm/llvm-project/pull/100292.diff

2 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.td (-1)
  • (modified) llvm/test/CodeGen/LoongArch/rotl-rotr.ll (+36)
diff --git a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
index 97f0e8d6a10c7..ec0d071453c3f 100644
--- a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -1144,7 +1144,6 @@ def : PatGprGpr<urem, MOD_DU>;
 def : PatGprGpr<loongarch_mod_wu, MOD_WU>;
 def : PatGprGpr<rotr, ROTR_D>;
 def : PatGprGpr<loongarch_rotr_w, ROTR_W>;
-def : PatGprGpr_32<rotr, ROTR_W>;
 def : PatGprImm<rotr, ROTRI_D, uimm6>;
 def : PatGprImm_32<rotr, ROTRI_W, uimm5>;
 def : PatGprImm<loongarch_rotr_w, ROTRI_W, uimm5>;
diff --git a/llvm/test/CodeGen/LoongArch/rotl-rotr.ll b/llvm/test/CodeGen/LoongArch/rotl-rotr.ll
index b2d46f5c088ba..75461f5820984 100644
--- a/llvm/test/CodeGen/LoongArch/rotl-rotr.ll
+++ b/llvm/test/CodeGen/LoongArch/rotl-rotr.ll
@@ -504,6 +504,42 @@ define i64 @rotr_64_mask_or_128_or_64(i64 %x, i64 %y) nounwind {
   ret i64 %f
 }
 
+define signext i32 @rotr_64_trunc_32(i64 %x, i64 %y) nounwind {
+; LA32-LABEL: rotr_64_trunc_32:
+; LA32:       # %bb.0:
+; LA32-NEXT:    srl.w $a3, $a0, $a2
+; LA32-NEXT:    xori $a4, $a2, 31
+; LA32-NEXT:    slli.w $a5, $a1, 1
+; LA32-NEXT:    sll.w $a4, $a5, $a4
+; LA32-NEXT:    or $a3, $a3, $a4
+; LA32-NEXT:    addi.w $a4, $a2, -32
+; LA32-NEXT:    slti $a5, $a4, 0
+; LA32-NEXT:    maskeqz $a3, $a3, $a5
+; LA32-NEXT:    srl.w $a1, $a1, $a4
+; LA32-NEXT:    masknez $a1, $a1, $a5
+; LA32-NEXT:    or $a1, $a3, $a1
+; LA32-NEXT:    sub.w $a3, $zero, $a2
+; LA32-NEXT:    sll.w $a0, $a0, $a3
+; LA32-NEXT:    ori $a3, $zero, 32
+; LA32-NEXT:    sub.w $a2, $a3, $a2
+; LA32-NEXT:    srai.w $a2, $a2, 31
+; LA32-NEXT:    and $a0, $a2, $a0
+; LA32-NEXT:    or $a0, $a1, $a0
+; LA32-NEXT:    ret
+;
+; LA64-LABEL: rotr_64_trunc_32:
+; LA64:       # %bb.0:
+; LA64-NEXT:    rotr.d $a0, $a0, $a1
+; LA64-NEXT:    addi.w $a0, $a0, 0
+; LA64-NEXT:    ret
+  %z = sub i64 64, %y
+  %b = lshr i64 %x, %y
+  %c = shl i64 %x, %z
+  %d = or i64 %b, %c
+  %e = trunc i64 %d to i32
+  ret i32 %e
+}
+
 define signext i32 @rotri_i32(i32 signext %a) nounwind {
 ; LA32-LABEL: rotri_i32:
 ; LA32:       # %bb.0:

@heiher heiher added this to the LLVM 19.X Release milestone Jul 24, 2024
@SixWeining
Copy link
Contributor

sext i64 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i32

Do you mean:
sext i32 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i64

@heiher
Copy link
Member Author

heiher commented Jul 24, 2024

sext i64 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i32

Do you mean: sext i32 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i64

Yeah.

@heiher heiher merged commit e386aac into llvm:main Jul 24, 2024
6 of 9 checks passed
@heiher heiher deleted the fix-rotr branch July 24, 2024 04:08
@heiher
Copy link
Member Author

heiher commented Jul 24, 2024

/cherry-pick e386aac

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 24, 2024
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)
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2024

/pull-request #100297

tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 24, 2024
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)
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
This patch fixes the code generation for IR:

sext i32 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i64

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250768
Harini0924 pushed a commit to Harini0924/llvm-project that referenced this pull request Aug 1, 2024
This patch fixes the code generation for IR:

sext i32 (trunc i64 (rotr i64 %x, i64 %y) to i32) to i64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants