[llvm] 6645bfa - [NVPTX] Fix bug with int_nvvm_rotate_b64 when operand immediate

Dmitry Vassiliev via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 14 14:24:04 PST 2022


Author: Dmitry Vassiliev
Date: 2022-02-15T01:23:11+03:00
New Revision: 6645bfa8f501fd7698ce584976bea9c99c49d64d

URL: https://github.com/llvm/llvm-project/commit/6645bfa8f501fd7698ce584976bea9c99c49d64d
DIFF: https://github.com/llvm/llvm-project/commit/6645bfa8f501fd7698ce584976bea9c99c49d64d.diff

LOG: [NVPTX] Fix bug with int_nvvm_rotate_b64 when operand immediate

Need to subract from 64, not 32.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D119639

Added: 
    llvm/test/CodeGen/NVPTX/rotate_64.ll

Modified: 
    llvm/lib/Target/NVPTX/NVPTXIntrinsics.td

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td b/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
index ec069a0a02ae7..479b0143ab7cc 100644
--- a/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ b/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -2473,7 +2473,7 @@ def : Pat<(int_nvvm_rotate_right_b64 Int64Regs:$src, Int32Regs:$amt),
 
 // SW version of rotate 64
 def : Pat<(int_nvvm_rotate_b64 Int64Regs:$src, (i32 imm:$amt)),
-          (ROT64imm_sw Int64Regs:$src, imm:$amt, (SUB_FRM_32 node:$amt))>,
+          (ROT64imm_sw Int64Regs:$src, imm:$amt, (SUB_FRM_64 node:$amt))>,
       Requires<[noHWROT32]>;
 def : Pat<(int_nvvm_rotate_b64 Int64Regs:$src, Int32Regs:$amt),
           (ROTL64reg_sw Int64Regs:$src, Int32Regs:$amt)>,

diff  --git a/llvm/test/CodeGen/NVPTX/rotate_64.ll b/llvm/test/CodeGen/NVPTX/rotate_64.ll
new file mode 100644
index 0000000000000..1ba0dfa90e021
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/rotate_64.ll
@@ -0,0 +1,25 @@
+; RUN: llc < %s -march=nvptx | FileCheck %s
+
+
+declare i64 @llvm.nvvm.rotate.b64(i64, i32)
+declare i64 @llvm.nvvm.rotate.right.b64(i64, i32)
+
+; CHECK: rotate64
+define i64 @rotate64(i64 %a, i32 %b) {
+; CHECK: shl.b64         [[LHS:%.*]], [[RD1:%.*]], 3;
+; CHECK: shr.b64         [[RHS:%.*]], [[RD1]], 61;
+; CHECK: add.u64         [[RD2:%.*]], [[LHS]], [[RHS]];
+; CHECK: ret
+  %val = tail call i64 @llvm.nvvm.rotate.b64(i64 %a, i32 3)
+  ret i64 %val
+}
+
+; CHECK: rotateright64
+define i64 @rotateright64(i64 %a, i32 %b) {
+; CHECK: shl.b64         [[LHS:%.*]], [[RD1:%.*]], 61;
+; CHECK: shr.b64         [[RHS:%.*]], [[RD1]], 3;
+; CHECK: add.u64         [[RD2:%.*]], [[LHS]], [[RHS]];
+; CHECK: ret
+  %val = tail call i64 @llvm.nvvm.rotate.right.b64(i64 %a, i32 3)
+  ret i64 %val
+}


        


More information about the llvm-commits mailing list