diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp @@ -141,6 +141,30 @@ Res.push_back(RISCVMatInt::Inst(RISCV::ADDI, Lo12)); } +static bool extractRotateInfo(int64_t Val, int &NegImm12, int &Rotate) { + // for case: 0b111..1..xxxxxx1..1.. + unsigned LeadingOnes = countLeadingOnes((uint64_t)Val); + unsigned TrailingOnes = countTrailingOnes((uint64_t)Val); + if (TrailingOnes > 0 && TrailingOnes < 64 && + (LeadingOnes + TrailingOnes) > (64 - 12)) { + NegImm12 = ((uint64_t)Val >> TrailingOnes) | + ((uint64_t)Val << (64 - TrailingOnes)); + Rotate = 64 - TrailingOnes; + return true; + } + // for case: 0bxxx1..1..1...xxx + unsigned UpperTrailingOnes = countTrailingOnes(Hi_32(Val)); + unsigned LowerLeadingOnes = countLeadingOnes(Lo_32(Val)); + if (UpperTrailingOnes > 0 && UpperTrailingOnes < 32 && + (UpperTrailingOnes + LowerLeadingOnes) > (64 - 12)) { + NegImm12 = ((uint64_t)Val << (32 - UpperTrailingOnes)) | + (((uint64_t)Val >> (32 + UpperTrailingOnes))); + Rotate = 32 - UpperTrailingOnes; + return true; + } + return false; +} + namespace llvm { namespace RISCVMatInt { InstSeq generateInstSeq(int64_t Val, const FeatureBitset &ActiveFeatures) { @@ -312,6 +336,17 @@ } } + // Perform optimization with rori in the Zbb extension. + if (Res.size() > 2 && ActiveFeatures[RISCV::FeatureStdExtZbb]) { + int NegImm12; + int Rotate; + if (extractRotateInfo(Val, NegImm12, Rotate)) { + RISCVMatInt::InstSeq TmpSeq; + TmpSeq.push_back(RISCVMatInt::Inst(RISCV::ADDI, NegImm12)); + TmpSeq.push_back(RISCVMatInt::Inst(RISCV::RORI, Rotate)); + Res = TmpSeq; + } + } return Res; } diff --git a/llvm/test/CodeGen/RISCV/imm.ll b/llvm/test/CodeGen/RISCV/imm.ll --- a/llvm/test/CodeGen/RISCV/imm.ll +++ b/llvm/test/CodeGen/RISCV/imm.ll @@ -5,6 +5,8 @@ ; RUN: | FileCheck %s -check-prefix=RV64I ; RUN: llc -mtriple=riscv64 -riscv-disable-using-constant-pool-for-large-ints -mattr=+experimental-zba \ ; RUN: -verify-machineinstrs < %s | FileCheck %s -check-prefix=RV64IZBA +; RUN: llc -mtriple=riscv64 -riscv-disable-using-constant-pool-for-large-ints -mattr=+experimental-zbb \ +; RUN: -verify-machineinstrs < %s | FileCheck %s -check-prefix=RV64IZBB ; RUN: llc -mtriple=riscv64 -riscv-disable-using-constant-pool-for-large-ints -mattr=+experimental-zbs \ ; RUN: -verify-machineinstrs < %s | FileCheck %s -check-prefix=RV64IZBS @@ -34,6 +36,11 @@ ; RV64IZBS: # %bb.0: ; RV64IZBS-NEXT: li a0, 0 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: zero: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, 0 +; RV64IZBB-NEXT: ret ret i32 0 } @@ -57,6 +64,11 @@ ; RV64IZBS: # %bb.0: ; RV64IZBS-NEXT: li a0, 2047 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: pos_small: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, 2047 +; RV64IZBB-NEXT: ret ret i32 2047 } @@ -80,6 +92,11 @@ ; RV64IZBS: # %bb.0: ; RV64IZBS-NEXT: li a0, -2048 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: neg_small: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -2048 +; RV64IZBB-NEXT: ret ret i32 -2048 } @@ -107,6 +124,12 @@ ; RV64IZBS-NEXT: lui a0, 423811 ; RV64IZBS-NEXT: addiw a0, a0, -1297 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: pos_i32: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 423811 +; RV64IZBB-NEXT: addiw a0, a0, -1297 +; RV64IZBB-NEXT: ret ret i32 1735928559 } @@ -134,6 +157,12 @@ ; RV64IZBS-NEXT: lui a0, 912092 ; RV64IZBS-NEXT: addiw a0, a0, -273 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: neg_i32: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 912092 +; RV64IZBB-NEXT: addiw a0, a0, -273 +; RV64IZBB-NEXT: ret ret i32 -559038737 } @@ -157,6 +186,11 @@ ; RV64IZBS: # %bb.0: ; RV64IZBS-NEXT: lui a0, 16 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: pos_i32_hi20_only: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 16 +; RV64IZBB-NEXT: ret ret i32 65536 ; 0x10000 } @@ -180,6 +214,11 @@ ; RV64IZBS: # %bb.0: ; RV64IZBS-NEXT: lui a0, 1048560 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: neg_i32_hi20_only: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1048560 +; RV64IZBB-NEXT: ret ret i32 -65536 ; -0x10000 } @@ -209,6 +248,12 @@ ; RV64IZBS-NEXT: lui a0, 32 ; RV64IZBS-NEXT: addiw a0, a0, -64 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_left_shifted_addi: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 32 +; RV64IZBB-NEXT: addiw a0, a0, -64 +; RV64IZBB-NEXT: ret ret i32 131008 ; 0x1FFC0 } @@ -238,6 +283,12 @@ ; RV64IZBS-NEXT: lui a0, 524288 ; RV64IZBS-NEXT: addiw a0, a0, -1 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_right_shifted_addi: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 524288 +; RV64IZBB-NEXT: addiw a0, a0, -1 +; RV64IZBB-NEXT: ret ret i32 2147483647 ; 0x7FFFFFFF } @@ -267,6 +318,12 @@ ; RV64IZBS-NEXT: lui a0, 56 ; RV64IZBS-NEXT: addiw a0, a0, 580 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_right_shifted_lui: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 56 +; RV64IZBB-NEXT: addiw a0, a0, 580 +; RV64IZBB-NEXT: ret ret i32 229956 ; 0x38244 } @@ -294,6 +351,12 @@ ; RV64IZBS-NEXT: li a0, 1 ; RV64IZBS-NEXT: slli a0, a0, 31 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, 1 +; RV64IZBB-NEXT: slli a0, a0, 31 +; RV64IZBB-NEXT: ret ret i64 2147483648 ; 0x8000_0000 } @@ -321,6 +384,12 @@ ; RV64IZBS-NEXT: li a0, -1 ; RV64IZBS-NEXT: srli a0, a0, 32 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_2: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: srli a0, a0, 32 +; RV64IZBB-NEXT: ret ret i64 4294967295 ; 0xFFFF_FFFF } @@ -348,6 +417,12 @@ ; RV64IZBS-NEXT: li a0, 1 ; RV64IZBS-NEXT: slli a0, a0, 32 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_3: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, 1 +; RV64IZBB-NEXT: slli a0, a0, 32 +; RV64IZBB-NEXT: ret ret i64 4294967296 ; 0x1_0000_0000 } @@ -375,6 +450,12 @@ ; RV64IZBS-NEXT: li a0, -1 ; RV64IZBS-NEXT: slli a0, a0, 63 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_4: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: slli a0, a0, 63 +; RV64IZBB-NEXT: ret ret i64 9223372036854775808 ; 0x8000_0000_0000_0000 } @@ -402,6 +483,12 @@ ; RV64IZBS-NEXT: li a0, -1 ; RV64IZBS-NEXT: slli a0, a0, 63 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_5: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: slli a0, a0, 63 +; RV64IZBB-NEXT: ret ret i64 -9223372036854775808 ; 0x8000_0000_0000_0000 } @@ -433,6 +520,13 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1329 ; RV64IZBS-NEXT: slli a0, a0, 35 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_6: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 9321 +; RV64IZBB-NEXT: addiw a0, a0, -1329 +; RV64IZBB-NEXT: slli a0, a0, 35 +; RV64IZBB-NEXT: ret ret i64 1311768464867721216 ; 0x1234_5678_0000_0000 } @@ -470,6 +564,15 @@ ; RV64IZBS-NEXT: slli a0, a0, 24 ; RV64IZBS-NEXT: addi a0, a0, 15 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_7: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, 7 +; RV64IZBB-NEXT: slli a0, a0, 36 +; RV64IZBB-NEXT: addi a0, a0, 11 +; RV64IZBB-NEXT: slli a0, a0, 24 +; RV64IZBB-NEXT: addi a0, a0, 15 +; RV64IZBB-NEXT: ret ret i64 8070450532432478223 ; 0x7000_0000_0B00_000F } @@ -519,6 +622,18 @@ ; RV64IZBS-NEXT: slli a0, a0, 13 ; RV64IZBS-NEXT: addi a0, a0, -272 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_8: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 583 +; RV64IZBB-NEXT: addiw a0, a0, -1875 +; RV64IZBB-NEXT: slli a0, a0, 14 +; RV64IZBB-NEXT: addi a0, a0, -947 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1511 +; RV64IZBB-NEXT: slli a0, a0, 13 +; RV64IZBB-NEXT: addi a0, a0, -272 +; RV64IZBB-NEXT: ret ret i64 1311768467463790320 ; 0x1234_5678_9ABC_DEF0 } @@ -543,6 +658,11 @@ ; RV64IZBS: # %bb.0: ; RV64IZBS-NEXT: li a0, -1 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm64_9: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: ret ret i64 -1 } @@ -573,6 +693,12 @@ ; RV64IZBS-NEXT: lui a0, 262145 ; RV64IZBS-NEXT: slli a0, a0, 1 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_left_shifted_lui_1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 262145 +; RV64IZBB-NEXT: slli a0, a0, 1 +; RV64IZBB-NEXT: ret ret i64 2147491840 ; 0x8000_2000 } @@ -600,6 +726,12 @@ ; RV64IZBS-NEXT: lui a0, 262145 ; RV64IZBS-NEXT: slli a0, a0, 2 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_left_shifted_lui_2: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 262145 +; RV64IZBB-NEXT: slli a0, a0, 2 +; RV64IZBB-NEXT: ret ret i64 4294983680 ; 0x1_0000_4000 } @@ -628,6 +760,12 @@ ; RV64IZBS-NEXT: lui a0, 4097 ; RV64IZBS-NEXT: slli a0, a0, 20 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_left_shifted_lui_3: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 4097 +; RV64IZBB-NEXT: slli a0, a0, 20 +; RV64IZBB-NEXT: ret ret i64 17596481011712 ; 0x1001_0000_0000 } @@ -660,6 +798,12 @@ ; RV64IZBS-NEXT: lui a0, 983056 ; RV64IZBS-NEXT: srli a0, a0, 16 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_right_shifted_lui_1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 983056 +; RV64IZBB-NEXT: srli a0, a0, 16 +; RV64IZBB-NEXT: ret ret i64 281474976706561 ; 0xFFFF_FFFF_F001 } @@ -691,6 +835,13 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: srli a0, a0, 24 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_right_shifted_lui_2: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1044481 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: srli a0, a0, 24 +; RV64IZBB-NEXT: ret ret i64 1099511623681 ; 0xFF_FFFF_F001 } @@ -724,6 +875,13 @@ ; RV64IZBS-NEXT: slli a0, a0, 20 ; RV64IZBS-NEXT: addi a0, a0, -3 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_decoupled_lui_addi: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 4097 +; RV64IZBB-NEXT: slli a0, a0, 20 +; RV64IZBB-NEXT: addi a0, a0, -3 +; RV64IZBB-NEXT: ret ret i64 17596481011709 ; 0x1000_FFFF_FFFD } @@ -763,6 +921,15 @@ ; RV64IZBS-NEXT: slli a0, a0, 25 ; RV64IZBS-NEXT: addi a0, a0, -1 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_end_xori_1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: slli a0, a0, 36 +; RV64IZBB-NEXT: addi a0, a0, 1 +; RV64IZBB-NEXT: slli a0, a0, 25 +; RV64IZBB-NEXT: addi a0, a0, -1 +; RV64IZBB-NEXT: ret ret i64 -2305843009180139521 ; 0xE000_0000_01FF_FFFF } @@ -803,6 +970,15 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, 2047 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_end_2addi_1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -2047 +; RV64IZBB-NEXT: slli a0, a0, 27 +; RV64IZBB-NEXT: addi a0, a0, -1 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 2047 +; RV64IZBB-NEXT: ret ret i64 -1125350151030785 ; 0xFFFC_007F_FFFF_F7FF } @@ -848,6 +1024,17 @@ ; RV64IZBS-NEXT: bseti a0, a0, 62 ; RV64IZBS-NEXT: bseti a0, a0, 63 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_2reg_1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: slli a0, a0, 35 +; RV64IZBB-NEXT: addi a0, a0, 9 +; RV64IZBB-NEXT: slli a0, a0, 13 +; RV64IZBB-NEXT: addi a0, a0, 837 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1656 +; RV64IZBB-NEXT: ret ret i64 -1152921504301427080 ; 0xF000_0000_1234_5678 } @@ -876,6 +1063,12 @@ ; RV64IZBS-NEXT: li a1, -1 ; RV64IZBS-NEXT: sh a1, 0(a0) ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_store_i16_neg1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a1, -1 +; RV64IZBB-NEXT: sh a1, 0(a0) +; RV64IZBB-NEXT: ret store i16 -1, i16* %p ret void } @@ -905,6 +1098,12 @@ ; RV64IZBS-NEXT: li a1, -1 ; RV64IZBS-NEXT: sw a1, 0(a0) ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_store_i32_neg1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a1, -1 +; RV64IZBB-NEXT: sw a1, 0(a0) +; RV64IZBB-NEXT: ret store i32 -1, i32* %p ret void } @@ -938,6 +1137,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, -795 ; RV64IZBS-NEXT: bseti a0, a0, 32 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_5372288229: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 160 +; RV64IZBB-NEXT: addiw a0, a0, 437 +; RV64IZBB-NEXT: slli a0, a0, 13 +; RV64IZBB-NEXT: addi a0, a0, -795 +; RV64IZBB-NEXT: ret ret i64 5372288229 } @@ -970,6 +1177,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, 795 ; RV64IZBS-NEXT: bclri a0, a0, 32 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_5372288229: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1048416 +; RV64IZBB-NEXT: addiw a0, a0, -437 +; RV64IZBB-NEXT: slli a0, a0, 13 +; RV64IZBB-NEXT: addi a0, a0, 795 +; RV64IZBB-NEXT: ret ret i64 -5372288229 } @@ -1002,6 +1217,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1325 ; RV64IZBS-NEXT: bseti a0, a0, 33 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_8953813715: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 267 +; RV64IZBB-NEXT: addiw a0, a0, -637 +; RV64IZBB-NEXT: slli a0, a0, 13 +; RV64IZBB-NEXT: addi a0, a0, -1325 +; RV64IZBB-NEXT: ret ret i64 8953813715 } @@ -1034,6 +1257,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, 1325 ; RV64IZBS-NEXT: bclri a0, a0, 33 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_8953813715: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1048309 +; RV64IZBB-NEXT: addiw a0, a0, 637 +; RV64IZBB-NEXT: slli a0, a0, 13 +; RV64IZBB-NEXT: addi a0, a0, 1325 +; RV64IZBB-NEXT: ret ret i64 -8953813715 } @@ -1067,6 +1298,14 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, 1711 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_16116864687: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 961 +; RV64IZBB-NEXT: addiw a0, a0, -1475 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1711 +; RV64IZBB-NEXT: ret ret i64 16116864687 } @@ -1100,6 +1339,14 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, -1711 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_16116864687: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1047615 +; RV64IZBB-NEXT: addiw a0, a0, 1475 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -1711 +; RV64IZBB-NEXT: ret ret i64 -16116864687 } @@ -1131,6 +1378,13 @@ ; RV64IZBS-NEXT: slli a0, a0, 2 ; RV64IZBS-NEXT: addi a0, a0, -1093 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_2344336315: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 143087 +; RV64IZBB-NEXT: slli a0, a0, 2 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: ret ret i64 2344336315 ; 0x8bbbbbbb } @@ -1168,6 +1422,16 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1093 ; RV64IZBS-NEXT: bseti a0, a0, 46 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_70370820078523: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 256 +; RV64IZBB-NEXT: addiw a0, a0, 31 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -273 +; RV64IZBB-NEXT: slli a0, a0, 14 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: ret ret i64 70370820078523 ; 0x40007bbbbbbb } @@ -1207,6 +1471,17 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1093 ; RV64IZBS-NEXT: bseti a0, a0, 63 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_9223372034778874949: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: slli a0, a0, 37 +; RV64IZBB-NEXT: addi a0, a0, 31 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -273 +; RV64IZBB-NEXT: slli a0, a0, 14 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: ret ret i64 -9223372034778874949 ; 0x800000007bbbbbbb } @@ -1247,6 +1522,17 @@ ; RV64IZBS-NEXT: bseti a0, a0, 46 ; RV64IZBS-NEXT: bseti a0, a0, 63 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_9223301666034697285: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 917505 +; RV64IZBB-NEXT: slli a0, a0, 8 +; RV64IZBB-NEXT: addi a0, a0, 31 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -273 +; RV64IZBB-NEXT: slli a0, a0, 14 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: ret ret i64 -9223301666034697285 ; 0x800040007bbbbbbb } @@ -1278,6 +1564,13 @@ ; RV64IZBS-NEXT: slli a0, a0, 2 ; RV64IZBS-NEXT: addi a0, a0, -1093 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_2219066437: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 913135 +; RV64IZBB-NEXT: slli a0, a0, 2 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: ret ret i64 -2219066437 ; 0xffffffff7bbbbbbb } @@ -1312,6 +1605,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1093 ; RV64IZBS-NEXT: bclri a0, a0, 43 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_8798043653189: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 917475 +; RV64IZBB-NEXT: addiw a0, a0, -273 +; RV64IZBB-NEXT: slli a0, a0, 14 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: ret ret i64 -8798043653189 ; 0xfffff7ff8bbbbbbb } @@ -1348,6 +1649,15 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1093 ; RV64IZBS-NEXT: bclri a0, a0, 63 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_9223372034904144827: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1048343 +; RV64IZBB-NEXT: addiw a0, a0, 1911 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1911 +; RV64IZBB-NEXT: srli a0, a0, 1 +; RV64IZBB-NEXT: ret ret i64 9223372034904144827 ; 0x7fffffff8bbbbbbb } @@ -1389,6 +1699,17 @@ ; RV64IZBS-NEXT: bclri a0, a0, 44 ; RV64IZBS-NEXT: bclri a0, a0, 63 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_9223354442718100411: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 524287 +; RV64IZBB-NEXT: slli a0, a0, 6 +; RV64IZBB-NEXT: addi a0, a0, -29 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -273 +; RV64IZBB-NEXT: slli a0, a0, 14 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: ret ret i64 9223354442718100411 ; 0x7fffefff8bbbbbbb } @@ -1421,6 +1742,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1366 ; RV64IZBS-NEXT: bseti a0, a0, 31 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_2863311530: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 171 +; RV64IZBB-NEXT: addiw a0, a0, -1365 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -1366 +; RV64IZBB-NEXT: ret ret i64 2863311530 ; #0xaaaaaaaa } @@ -1453,6 +1782,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, 1366 ; RV64IZBS-NEXT: bclri a0, a0, 31 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_2863311530: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1048405 +; RV64IZBB-NEXT: addiw a0, a0, 1365 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1366 +; RV64IZBB-NEXT: ret ret i64 -2863311530 ; #0xffffffff55555556 } @@ -1483,6 +1820,13 @@ ; RV64IZBS-NEXT: li a0, 1365 ; RV64IZBS-NEXT: bseti a0, a0, 31 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_2147486378: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, 1 +; RV64IZBB-NEXT: slli a0, a0, 31 +; RV64IZBB-NEXT: addi a0, a0, 1365 +; RV64IZBB-NEXT: ret ret i64 2147485013 } @@ -1513,6 +1857,13 @@ ; RV64IZBS-NEXT: li a0, -1365 ; RV64IZBS-NEXT: bclri a0, a0, 31 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_2147485013: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -1 +; RV64IZBB-NEXT: slli a0, a0, 31 +; RV64IZBB-NEXT: addi a0, a0, -1365 +; RV64IZBB-NEXT: ret ret i64 -2147485013 } @@ -1547,6 +1898,14 @@ ; RV64IZBS-NEXT: slli a0, a0, 24 ; RV64IZBS-NEXT: addi a0, a0, 1979 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_12900924131259: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 188 +; RV64IZBB-NEXT: addiw a0, a0, -1093 +; RV64IZBB-NEXT: slli a0, a0, 24 +; RV64IZBB-NEXT: addi a0, a0, 1979 +; RV64IZBB-NEXT: ret ret i64 12900924131259 } @@ -1576,6 +1935,13 @@ ; RV64IZBS-NEXT: addiw a0, a0, -1093 ; RV64IZBS-NEXT: slli a0, a0, 16 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_50394234880: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 188 +; RV64IZBB-NEXT: addiw a0, a0, -1093 +; RV64IZBB-NEXT: slli a0, a0, 16 +; RV64IZBB-NEXT: ret ret i64 50394234880 } @@ -1613,6 +1979,15 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, 1911 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_12900936431479: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 192239 +; RV64IZBB-NEXT: slli a0, a0, 2 +; RV64IZBB-NEXT: addi a0, a0, -1093 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1911 +; RV64IZBB-NEXT: ret ret i64 12900936431479 } @@ -1652,6 +2027,16 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, -1366 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_12900918536874: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 188 +; RV64IZBB-NEXT: addiw a0, a0, -1093 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -1365 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, -1366 +; RV64IZBB-NEXT: ret ret i64 12900918536874 } @@ -1691,6 +2076,16 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, 273 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_12900925247761: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 188 +; RV64IZBB-NEXT: addiw a0, a0, -1093 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 273 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 273 +; RV64IZBB-NEXT: ret ret i64 12900925247761 } @@ -1724,6 +2119,14 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, 1 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_7158272001: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 427 +; RV64IZBB-NEXT: addiw a0, a0, -1367 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1 +; RV64IZBB-NEXT: ret ret i64 7158272001 ; 0x0000_0001_aaaa_9001 } @@ -1757,6 +2160,14 @@ ; RV64IZBS-NEXT: slli a0, a0, 12 ; RV64IZBS-NEXT: addi a0, a0, 1 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_12884889601: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 768 +; RV64IZBB-NEXT: addiw a0, a0, -3 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1 +; RV64IZBB-NEXT: ret ret i64 12884889601 ; 0x0000_0002_ffff_d001 } @@ -1789,6 +2200,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, 1 ; RV64IZBS-NEXT: bclri a0, a0, 31 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_3435982847: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1048371 +; RV64IZBB-NEXT: addiw a0, a0, 817 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1 +; RV64IZBB-NEXT: ret ret i64 -3435982847 ; 0xffff_ffff_3333_1001 } @@ -1821,6 +2240,14 @@ ; RV64IZBS-NEXT: addiw a0, a0, 1 ; RV64IZBS-NEXT: bclri a0, a0, 32 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_5726842879: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1048235 +; RV64IZBB-NEXT: addiw a0, a0, -1419 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1 +; RV64IZBB-NEXT: ret ret i64 -5726842879 ; 0xffff_fffe_aaa7_5001 } @@ -1853,5 +2280,122 @@ ; RV64IZBS-NEXT: addiw a0, a0, 1 ; RV64IZBS-NEXT: bclri a0, a0, 33 ; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: imm_neg_10307948543: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: lui a0, 1047962 +; RV64IZBB-NEXT: addiw a0, a0, -1645 +; RV64IZBB-NEXT: slli a0, a0, 12 +; RV64IZBB-NEXT: addi a0, a0, 1 +; RV64IZBB-NEXT: ret ret i64 -10307948543 ; 0xffff_fffd_9999_3001 } + +define i64 @li_rori_1() { +; RV32I-LABEL: li_rori_1: +; RV32I: # %bb.0: +; RV32I-NEXT: lui a0, 1048567 +; RV32I-NEXT: addi a1, a0, 2047 +; RV32I-NEXT: li a0, -1 +; RV32I-NEXT: ret +; +; RV64I-LABEL: li_rori_1: +; RV64I: # %bb.0: +; RV64I-NEXT: li a0, -17 +; RV64I-NEXT: slli a0, a0, 43 +; RV64I-NEXT: addi a0, a0, -1 +; RV64I-NEXT: ret +; +; RV64IZBA-LABEL: li_rori_1: +; RV64IZBA: # %bb.0: +; RV64IZBA-NEXT: li a0, -17 +; RV64IZBA-NEXT: slli a0, a0, 43 +; RV64IZBA-NEXT: addi a0, a0, -1 +; RV64IZBA-NEXT: ret +; +; RV64IZBS-LABEL: li_rori_1: +; RV64IZBS: # %bb.0: +; RV64IZBS-NEXT: li a0, -17 +; RV64IZBS-NEXT: slli a0, a0, 43 +; RV64IZBS-NEXT: addi a0, a0, -1 +; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: li_rori_1: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -18 +; RV64IZBB-NEXT: rori a0, a0, 21 +; RV64IZBB-NEXT: ret + ret i64 -149533581377537 +} +define i64 @li_rori_2() { +; RV32I-LABEL: li_rori_2: +; RV32I: # %bb.0: +; RV32I-NEXT: lui a0, 720896 +; RV32I-NEXT: addi a1, a0, -1 +; RV32I-NEXT: li a0, -6 +; RV32I-NEXT: ret +; +; RV64I-LABEL: li_rori_2: +; RV64I: # %bb.0: +; RV64I-NEXT: li a0, -5 +; RV64I-NEXT: slli a0, a0, 60 +; RV64I-NEXT: addi a0, a0, -6 +; RV64I-NEXT: ret +; +; RV64IZBA-LABEL: li_rori_2: +; RV64IZBA: # %bb.0: +; RV64IZBA-NEXT: li a0, -5 +; RV64IZBA-NEXT: slli a0, a0, 60 +; RV64IZBA-NEXT: addi a0, a0, -6 +; RV64IZBA-NEXT: ret +; +; RV64IZBS-LABEL: li_rori_2: +; RV64IZBS: # %bb.0: +; RV64IZBS-NEXT: li a0, -5 +; RV64IZBS-NEXT: slli a0, a0, 60 +; RV64IZBS-NEXT: addi a0, a0, -6 +; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: li_rori_2: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -86 +; RV64IZBB-NEXT: rori a0, a0, 4 +; RV64IZBB-NEXT: ret + ret i64 -5764607523034234886 +} +define i64 @li_rori_3() { +; RV32I-LABEL: li_rori_3: +; RV32I: # %bb.0: +; RV32I-NEXT: lui a0, 491520 +; RV32I-NEXT: addi a0, a0, -1 +; RV32I-NEXT: li a1, -1 +; RV32I-NEXT: ret +; +; RV64I-LABEL: li_rori_3: +; RV64I: # %bb.0: +; RV64I-NEXT: li a0, -17 +; RV64I-NEXT: slli a0, a0, 27 +; RV64I-NEXT: addi a0, a0, -1 +; RV64I-NEXT: ret +; +; RV64IZBA-LABEL: li_rori_3: +; RV64IZBA: # %bb.0: +; RV64IZBA-NEXT: li a0, -17 +; RV64IZBA-NEXT: slli a0, a0, 27 +; RV64IZBA-NEXT: addi a0, a0, -1 +; RV64IZBA-NEXT: ret +; +; RV64IZBS-LABEL: li_rori_3: +; RV64IZBS: # %bb.0: +; RV64IZBS-NEXT: li a0, -17 +; RV64IZBS-NEXT: slli a0, a0, 27 +; RV64IZBS-NEXT: addi a0, a0, -1 +; RV64IZBS-NEXT: ret +; +; RV64IZBB-LABEL: li_rori_3: +; RV64IZBB: # %bb.0: +; RV64IZBB-NEXT: li a0, -18 +; RV64IZBB-NEXT: rori a0, a0, 37 +; RV64IZBB-NEXT: ret + ret i64 -2281701377 +} diff --git a/llvm/test/MC/RISCV/rv64zbb-valid.s b/llvm/test/MC/RISCV/rv64zbb-valid.s --- a/llvm/test/MC/RISCV/rv64zbb-valid.s +++ b/llvm/test/MC/RISCV/rv64zbb-valid.s @@ -14,3 +14,13 @@ # CHECK-ASM-AND-OBJ: cpopw t0, t1 # CHECK-ASM: encoding: [0x9b,0x12,0x23,0x60] cpopw t0, t1 + +# CHECK-ASM-AND-OBJ: addi t0, zero, -18 +# CHECK-ASM-AND-OBJ: rori t0, t0, 21 +li t0, -149533581377537 +# CHECK-ASM-AND-OBJ: addi t0, zero, -86 +# CHECK-ASM-AND-OBJ: rori t0, t0, 4 +li t0, -5764607523034234886 +# CHECK-ASM-AND-OBJ: addi t0, zero, -18 +# CHECK-ASM-AND-OBJ: rori t0, t0, 37 +li t0, -2281701377