aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2022-08-30 11:59:37 -0700
committerCraig Topper <craig.topper@sifive.com>2022-08-30 12:22:46 -0700
commit893f5e95e254e000222513b5fea1921f1796145c (patch)
treea1fa256eb418e0773ca8b899fa37480133246b21
parentfd1f8c85f2c0b989d1ac3a05b920f5b5fa355645 (diff)
downloadllvm-893f5e95e254e000222513b5fea1921f1796145c.zip
llvm-893f5e95e254e000222513b5fea1921f1796145c.tar.gz
llvm-893f5e95e254e000222513b5fea1921f1796145c.tar.bz2
[RISCV] Improve isel of AND with shiftedMask containing 32 leading zeros and some trailing zeros.
We can use srliw to shift out the trailing bits and slli to shift back in zeros. The sign extend of srliw will 0 the upper 32 bits since we will be shifting a 0 into bit 31.
-rw-r--r--llvm/lib/Target/RISCV/RISCVInstrInfo.td16
-rw-r--r--llvm/test/CodeGen/RISCV/and.ll16
-rw-r--r--llvm/test/CodeGen/RISCV/bswap-bitreverse.ll96
-rw-r--r--llvm/test/CodeGen/RISCV/rv64zba.ll18
-rw-r--r--llvm/test/CodeGen/RISCV/rv64zbb.ll48
-rw-r--r--llvm/test/CodeGen/RISCV/rv64zbp.ll101
-rw-r--r--llvm/test/CodeGen/RISCV/vararg.ll24
7 files changed, 168 insertions, 151 deletions
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index 9c28881..ab68210 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -456,6 +456,19 @@ def TrailingOnesMask : PatLeaf<(imm), [{
return !isInt<12>(N->getSExtValue()) && isMask_64(N->getZExtValue());
}], XLenSubTrailingOnes>;
+// Similar to LeadingOnesMask, but only consider leading ones in the lower 32
+// bits.
+def LeadingOnesWMask : PatLeaf<(imm), [{
+ if (!N->hasOneUse())
+ return false;
+ // If the value is a uint32 but not an int32, it must have bit 31 set and
+ // bits 63:32 cleared. After that we're looking for a shifted mask but not
+ // an all ones mask.
+ int64_t Imm = N->getSExtValue();
+ return !isInt<32>(Imm) && isUInt<32>(Imm) && isShiftedMask_64(Imm) &&
+ Imm != UINT64_C(0xffffffff);
+}], TrailingZeros>;
+
//===----------------------------------------------------------------------===//
// Instruction Formats
//===----------------------------------------------------------------------===//
@@ -1593,6 +1606,9 @@ def u32simm12 : ImmLeaf<XLenVT, [{
let Predicates = [IsRV64] in {
+def : Pat<(i64 (and GPR:$rs, LeadingOnesWMask:$mask)),
+ (SLLI (SRLIW $rs, LeadingOnesWMask:$mask), LeadingOnesWMask:$mask)>;
+
/// sext and zext
// Sign extend is not needed if all users are W instructions.
diff --git a/llvm/test/CodeGen/RISCV/and.ll b/llvm/test/CodeGen/RISCV/and.ll
index ccf937a..d1d2e6a 100644
--- a/llvm/test/CodeGen/RISCV/and.ll
+++ b/llvm/test/CodeGen/RISCV/and.ll
@@ -218,3 +218,19 @@ define i64 @and64_0xffffffff80000000(i64 %x) {
%a = and i64 %x, -2147483648
ret i64 %a
}
+
+define i64 @and64_0x00000000fffffff8(i64 %x) {
+; RV32I-LABEL: and64_0x00000000fffffff8:
+; RV32I: # %bb.0:
+; RV32I-NEXT: andi a0, a0, -8
+; RV32I-NEXT: li a1, 0
+; RV32I-NEXT: ret
+;
+; RV64I-LABEL: and64_0x00000000fffffff8:
+; RV64I: # %bb.0:
+; RV64I-NEXT: srliw a0, a0, 3
+; RV64I-NEXT: slli a0, a0, 3
+; RV64I-NEXT: ret
+ %a = and i64 %x, 4294967288
+ ret i64 %a
+}
diff --git a/llvm/test/CodeGen/RISCV/bswap-bitreverse.ll b/llvm/test/CodeGen/RISCV/bswap-bitreverse.ll
index 7c9f9b9..a7cd363 100644
--- a/llvm/test/CodeGen/RISCV/bswap-bitreverse.ll
+++ b/llvm/test/CodeGen/RISCV/bswap-bitreverse.ll
@@ -152,34 +152,34 @@ define i64 @test_bswap_i64(i64 %a) nounwind {
;
; RV64I-LABEL: test_bswap_i64:
; RV64I: # %bb.0:
-; RV64I-NEXT: srli a1, a0, 24
-; RV64I-NEXT: lui a2, 4080
-; RV64I-NEXT: and a1, a1, a2
-; RV64I-NEXT: srli a2, a0, 8
-; RV64I-NEXT: li a3, 255
-; RV64I-NEXT: slli a4, a3, 24
-; RV64I-NEXT: and a2, a2, a4
+; RV64I-NEXT: slli a1, a0, 24
+; RV64I-NEXT: li a2, 255
+; RV64I-NEXT: slli a3, a2, 40
+; RV64I-NEXT: and a1, a1, a3
+; RV64I-NEXT: srliw a3, a0, 24
+; RV64I-NEXT: slli a3, a3, 32
+; RV64I-NEXT: or a1, a1, a3
+; RV64I-NEXT: slli a3, a0, 40
+; RV64I-NEXT: slli a2, a2, 48
+; RV64I-NEXT: and a2, a3, a2
+; RV64I-NEXT: slli a3, a0, 56
+; RV64I-NEXT: or a2, a3, a2
; RV64I-NEXT: or a1, a2, a1
; RV64I-NEXT: srli a2, a0, 40
-; RV64I-NEXT: lui a4, 16
-; RV64I-NEXT: addiw a4, a4, -256
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srli a4, a0, 56
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: or a1, a1, a2
-; RV64I-NEXT: slli a2, a0, 24
-; RV64I-NEXT: slli a4, a3, 40
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srliw a4, a0, 24
-; RV64I-NEXT: slli a4, a4, 32
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: slli a4, a0, 40
-; RV64I-NEXT: slli a3, a3, 48
-; RV64I-NEXT: and a3, a4, a3
-; RV64I-NEXT: slli a0, a0, 56
+; RV64I-NEXT: lui a3, 16
+; RV64I-NEXT: addiw a3, a3, -256
+; RV64I-NEXT: and a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 56
+; RV64I-NEXT: or a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 24
+; RV64I-NEXT: lui a4, 4080
+; RV64I-NEXT: and a3, a3, a4
+; RV64I-NEXT: srli a0, a0, 8
+; RV64I-NEXT: srliw a0, a0, 24
+; RV64I-NEXT: slli a0, a0, 24
; RV64I-NEXT: or a0, a0, a3
; RV64I-NEXT: or a0, a0, a2
-; RV64I-NEXT: or a0, a0, a1
+; RV64I-NEXT: or a0, a1, a0
; RV64I-NEXT: ret
;
; RV32ZB-LABEL: test_bswap_i64:
@@ -672,36 +672,36 @@ define i64 @test_bitreverse_i64(i64 %a) nounwind {
;
; RV64I-LABEL: test_bitreverse_i64:
; RV64I: # %bb.0:
-; RV64I-NEXT: srli a1, a0, 24
-; RV64I-NEXT: lui a2, 4080
-; RV64I-NEXT: and a1, a1, a2
-; RV64I-NEXT: srli a2, a0, 8
-; RV64I-NEXT: li a3, 255
-; RV64I-NEXT: slli a4, a3, 24
-; RV64I-NEXT: and a2, a2, a4
+; RV64I-NEXT: slli a1, a0, 24
+; RV64I-NEXT: li a2, 255
+; RV64I-NEXT: slli a3, a2, 40
+; RV64I-NEXT: and a1, a1, a3
+; RV64I-NEXT: srliw a3, a0, 24
+; RV64I-NEXT: slli a3, a3, 32
+; RV64I-NEXT: or a1, a1, a3
+; RV64I-NEXT: slli a3, a0, 40
+; RV64I-NEXT: slli a2, a2, 48
+; RV64I-NEXT: and a2, a3, a2
+; RV64I-NEXT: slli a3, a0, 56
+; RV64I-NEXT: or a2, a3, a2
; RV64I-NEXT: or a1, a2, a1
; RV64I-NEXT: srli a2, a0, 40
-; RV64I-NEXT: lui a4, 16
-; RV64I-NEXT: addiw a4, a4, -256
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srli a4, a0, 56
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: or a1, a1, a2
-; RV64I-NEXT: slli a2, a0, 24
-; RV64I-NEXT: slli a4, a3, 40
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srliw a4, a0, 24
-; RV64I-NEXT: slli a4, a4, 32
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: slli a4, a0, 40
-; RV64I-NEXT: slli a3, a3, 48
-; RV64I-NEXT: and a3, a4, a3
-; RV64I-NEXT: slli a0, a0, 56
+; RV64I-NEXT: lui a3, 16
+; RV64I-NEXT: addiw a3, a3, -256
+; RV64I-NEXT: and a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 56
+; RV64I-NEXT: or a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 24
+; RV64I-NEXT: lui a4, 4080
+; RV64I-NEXT: and a3, a3, a4
+; RV64I-NEXT: srli a0, a0, 8
+; RV64I-NEXT: srliw a0, a0, 24
+; RV64I-NEXT: slli a0, a0, 24
; RV64I-NEXT: or a0, a0, a3
; RV64I-NEXT: lui a3, %hi(.LCPI6_0)
; RV64I-NEXT: ld a3, %lo(.LCPI6_0)(a3)
; RV64I-NEXT: or a0, a0, a2
-; RV64I-NEXT: or a0, a0, a1
+; RV64I-NEXT: or a0, a1, a0
; RV64I-NEXT: srli a1, a0, 4
; RV64I-NEXT: and a1, a1, a3
; RV64I-NEXT: and a0, a0, a3
diff --git a/llvm/test/CodeGen/RISCV/rv64zba.ll b/llvm/test/CodeGen/RISCV/rv64zba.ll
index cd03b23..e9161ae 100644
--- a/llvm/test/CodeGen/RISCV/rv64zba.ll
+++ b/llvm/test/CodeGen/RISCV/rv64zba.ll
@@ -1389,10 +1389,8 @@ define i64 @sh3adduw_ptrdiff(i64 %diff, i64* %baseptr) {
define signext i16 @srliw_1_sh1add(i16* %0, i32 signext %1) {
; RV64I-LABEL: srliw_1_sh1add:
; RV64I: # %bb.0:
-; RV64I-NEXT: li a2, 1
-; RV64I-NEXT: slli a2, a2, 32
-; RV64I-NEXT: addi a2, a2, -2
-; RV64I-NEXT: and a1, a1, a2
+; RV64I-NEXT: srliw a1, a1, 1
+; RV64I-NEXT: slli a1, a1, 1
; RV64I-NEXT: add a0, a0, a1
; RV64I-NEXT: lh a0, 0(a0)
; RV64I-NEXT: ret
@@ -1413,10 +1411,8 @@ define signext i16 @srliw_1_sh1add(i16* %0, i32 signext %1) {
define signext i32 @srliw_2_sh2add(i32* %0, i32 signext %1) {
; RV64I-LABEL: srliw_2_sh2add:
; RV64I: # %bb.0:
-; RV64I-NEXT: li a2, 1
-; RV64I-NEXT: slli a2, a2, 32
-; RV64I-NEXT: addi a2, a2, -4
-; RV64I-NEXT: and a1, a1, a2
+; RV64I-NEXT: srliw a1, a1, 2
+; RV64I-NEXT: slli a1, a1, 2
; RV64I-NEXT: add a0, a0, a1
; RV64I-NEXT: lw a0, 0(a0)
; RV64I-NEXT: ret
@@ -1437,10 +1433,8 @@ define signext i32 @srliw_2_sh2add(i32* %0, i32 signext %1) {
define i64 @srliw_3_sh3add(i64* %0, i32 signext %1) {
; RV64I-LABEL: srliw_3_sh3add:
; RV64I: # %bb.0:
-; RV64I-NEXT: li a2, 1
-; RV64I-NEXT: slli a2, a2, 32
-; RV64I-NEXT: addi a2, a2, -8
-; RV64I-NEXT: and a1, a1, a2
+; RV64I-NEXT: srliw a1, a1, 3
+; RV64I-NEXT: slli a1, a1, 3
; RV64I-NEXT: add a0, a0, a1
; RV64I-NEXT: ld a0, 0(a0)
; RV64I-NEXT: ret
diff --git a/llvm/test/CodeGen/RISCV/rv64zbb.ll b/llvm/test/CodeGen/RISCV/rv64zbb.ll
index b66b2d7..e78bf62 100644
--- a/llvm/test/CodeGen/RISCV/rv64zbb.ll
+++ b/llvm/test/CodeGen/RISCV/rv64zbb.ll
@@ -1052,34 +1052,34 @@ declare i64 @llvm.bswap.i64(i64)
define i64 @bswap_i64(i64 %a) {
; RV64I-LABEL: bswap_i64:
; RV64I: # %bb.0:
-; RV64I-NEXT: srli a1, a0, 24
-; RV64I-NEXT: lui a2, 4080
-; RV64I-NEXT: and a1, a1, a2
-; RV64I-NEXT: srli a2, a0, 8
-; RV64I-NEXT: li a3, 255
-; RV64I-NEXT: slli a4, a3, 24
-; RV64I-NEXT: and a2, a2, a4
+; RV64I-NEXT: slli a1, a0, 24
+; RV64I-NEXT: li a2, 255
+; RV64I-NEXT: slli a3, a2, 40
+; RV64I-NEXT: and a1, a1, a3
+; RV64I-NEXT: srliw a3, a0, 24
+; RV64I-NEXT: slli a3, a3, 32
+; RV64I-NEXT: or a1, a1, a3
+; RV64I-NEXT: slli a3, a0, 40
+; RV64I-NEXT: slli a2, a2, 48
+; RV64I-NEXT: and a2, a3, a2
+; RV64I-NEXT: slli a3, a0, 56
+; RV64I-NEXT: or a2, a3, a2
; RV64I-NEXT: or a1, a2, a1
; RV64I-NEXT: srli a2, a0, 40
-; RV64I-NEXT: lui a4, 16
-; RV64I-NEXT: addiw a4, a4, -256
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srli a4, a0, 56
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: or a1, a1, a2
-; RV64I-NEXT: slli a2, a0, 24
-; RV64I-NEXT: slli a4, a3, 40
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srliw a4, a0, 24
-; RV64I-NEXT: slli a4, a4, 32
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: slli a4, a0, 40
-; RV64I-NEXT: slli a3, a3, 48
-; RV64I-NEXT: and a3, a4, a3
-; RV64I-NEXT: slli a0, a0, 56
+; RV64I-NEXT: lui a3, 16
+; RV64I-NEXT: addiw a3, a3, -256
+; RV64I-NEXT: and a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 56
+; RV64I-NEXT: or a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 24
+; RV64I-NEXT: lui a4, 4080
+; RV64I-NEXT: and a3, a3, a4
+; RV64I-NEXT: srli a0, a0, 8
+; RV64I-NEXT: srliw a0, a0, 24
+; RV64I-NEXT: slli a0, a0, 24
; RV64I-NEXT: or a0, a0, a3
; RV64I-NEXT: or a0, a0, a2
-; RV64I-NEXT: or a0, a0, a1
+; RV64I-NEXT: or a0, a1, a0
; RV64I-NEXT: ret
;
; RV64ZBB-LABEL: bswap_i64:
diff --git a/llvm/test/CodeGen/RISCV/rv64zbp.ll b/llvm/test/CodeGen/RISCV/rv64zbp.ll
index 48c6878..5f1ac90 100644
--- a/llvm/test/CodeGen/RISCV/rv64zbp.ll
+++ b/llvm/test/CodeGen/RISCV/rv64zbp.ll
@@ -2503,34 +2503,34 @@ declare i64 @llvm.bswap.i64(i64)
define i64 @bswap_i64(i64 %a) {
; RV64I-LABEL: bswap_i64:
; RV64I: # %bb.0:
-; RV64I-NEXT: srli a1, a0, 24
-; RV64I-NEXT: lui a2, 4080
-; RV64I-NEXT: and a1, a1, a2
-; RV64I-NEXT: srli a2, a0, 8
-; RV64I-NEXT: li a3, 255
-; RV64I-NEXT: slli a4, a3, 24
-; RV64I-NEXT: and a2, a2, a4
+; RV64I-NEXT: slli a1, a0, 24
+; RV64I-NEXT: li a2, 255
+; RV64I-NEXT: slli a3, a2, 40
+; RV64I-NEXT: and a1, a1, a3
+; RV64I-NEXT: srliw a3, a0, 24
+; RV64I-NEXT: slli a3, a3, 32
+; RV64I-NEXT: or a1, a1, a3
+; RV64I-NEXT: slli a3, a0, 40
+; RV64I-NEXT: slli a2, a2, 48
+; RV64I-NEXT: and a2, a3, a2
+; RV64I-NEXT: slli a3, a0, 56
+; RV64I-NEXT: or a2, a3, a2
; RV64I-NEXT: or a1, a2, a1
; RV64I-NEXT: srli a2, a0, 40
-; RV64I-NEXT: lui a4, 16
-; RV64I-NEXT: addiw a4, a4, -256
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srli a4, a0, 56
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: or a1, a1, a2
-; RV64I-NEXT: slli a2, a0, 24
-; RV64I-NEXT: slli a4, a3, 40
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srliw a4, a0, 24
-; RV64I-NEXT: slli a4, a4, 32
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: slli a4, a0, 40
-; RV64I-NEXT: slli a3, a3, 48
-; RV64I-NEXT: and a3, a4, a3
-; RV64I-NEXT: slli a0, a0, 56
+; RV64I-NEXT: lui a3, 16
+; RV64I-NEXT: addiw a3, a3, -256
+; RV64I-NEXT: and a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 56
+; RV64I-NEXT: or a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 24
+; RV64I-NEXT: lui a4, 4080
+; RV64I-NEXT: and a3, a3, a4
+; RV64I-NEXT: srli a0, a0, 8
+; RV64I-NEXT: srliw a0, a0, 24
+; RV64I-NEXT: slli a0, a0, 24
; RV64I-NEXT: or a0, a0, a3
; RV64I-NEXT: or a0, a0, a2
-; RV64I-NEXT: or a0, a0, a1
+; RV64I-NEXT: or a0, a1, a0
; RV64I-NEXT: ret
;
; RV64ZBP-LABEL: bswap_i64:
@@ -2712,36 +2712,36 @@ declare i64 @llvm.bitreverse.i64(i64)
define i64 @bitreverse_i64(i64 %a) nounwind {
; RV64I-LABEL: bitreverse_i64:
; RV64I: # %bb.0:
-; RV64I-NEXT: srli a1, a0, 24
-; RV64I-NEXT: lui a2, 4080
-; RV64I-NEXT: and a1, a1, a2
-; RV64I-NEXT: srli a2, a0, 8
-; RV64I-NEXT: li a3, 255
-; RV64I-NEXT: slli a4, a3, 24
-; RV64I-NEXT: and a2, a2, a4
+; RV64I-NEXT: slli a1, a0, 24
+; RV64I-NEXT: li a2, 255
+; RV64I-NEXT: slli a3, a2, 40
+; RV64I-NEXT: and a1, a1, a3
+; RV64I-NEXT: srliw a3, a0, 24
+; RV64I-NEXT: slli a3, a3, 32
+; RV64I-NEXT: or a1, a1, a3
+; RV64I-NEXT: slli a3, a0, 40
+; RV64I-NEXT: slli a2, a2, 48
+; RV64I-NEXT: and a2, a3, a2
+; RV64I-NEXT: slli a3, a0, 56
+; RV64I-NEXT: or a2, a3, a2
; RV64I-NEXT: or a1, a2, a1
; RV64I-NEXT: srli a2, a0, 40
-; RV64I-NEXT: lui a4, 16
-; RV64I-NEXT: addiw a4, a4, -256
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srli a4, a0, 56
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: or a1, a1, a2
-; RV64I-NEXT: slli a2, a0, 24
-; RV64I-NEXT: slli a4, a3, 40
-; RV64I-NEXT: and a2, a2, a4
-; RV64I-NEXT: srliw a4, a0, 24
-; RV64I-NEXT: slli a4, a4, 32
-; RV64I-NEXT: or a2, a2, a4
-; RV64I-NEXT: slli a4, a0, 40
-; RV64I-NEXT: slli a3, a3, 48
-; RV64I-NEXT: and a3, a4, a3
-; RV64I-NEXT: slli a0, a0, 56
+; RV64I-NEXT: lui a3, 16
+; RV64I-NEXT: addiw a3, a3, -256
+; RV64I-NEXT: and a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 56
+; RV64I-NEXT: or a2, a2, a3
+; RV64I-NEXT: srli a3, a0, 24
+; RV64I-NEXT: lui a4, 4080
+; RV64I-NEXT: and a3, a3, a4
+; RV64I-NEXT: srli a0, a0, 8
+; RV64I-NEXT: srliw a0, a0, 24
+; RV64I-NEXT: slli a0, a0, 24
; RV64I-NEXT: or a0, a0, a3
; RV64I-NEXT: lui a3, %hi(.LCPI73_0)
; RV64I-NEXT: ld a3, %lo(.LCPI73_0)(a3)
; RV64I-NEXT: or a0, a0, a2
-; RV64I-NEXT: or a0, a0, a1
+; RV64I-NEXT: or a0, a1, a0
; RV64I-NEXT: srli a1, a0, 4
; RV64I-NEXT: and a1, a1, a3
; RV64I-NEXT: and a0, a0, a3
@@ -3251,9 +3251,8 @@ define i64 @shfl16(i64 %a, i64 %b) nounwind {
; RV64I-NEXT: slli a2, a2, 32
; RV64I-NEXT: or a1, a2, a1
; RV64I-NEXT: srli a0, a0, 16
-; RV64I-NEXT: lui a2, 65535
-; RV64I-NEXT: slli a2, a2, 4
-; RV64I-NEXT: and a0, a0, a2
+; RV64I-NEXT: srliw a0, a0, 16
+; RV64I-NEXT: slli a0, a0, 16
; RV64I-NEXT: or a0, a1, a0
; RV64I-NEXT: ret
;
diff --git a/llvm/test/CodeGen/RISCV/vararg.ll b/llvm/test/CodeGen/RISCV/vararg.ll
index cad6d19..1238460 100644
--- a/llvm/test/CodeGen/RISCV/vararg.ll
+++ b/llvm/test/CodeGen/RISCV/vararg.ll
@@ -569,10 +569,8 @@ define i64 @va2(i8 *%fmt, ...) nounwind {
; LP64-LP64F-LP64D-FPELIM-NEXT: srli a1, a1, 32
; LP64-LP64F-LP64D-FPELIM-NEXT: addi a1, a1, 8
; LP64-LP64F-LP64D-FPELIM-NEXT: sd a1, 8(sp)
-; LP64-LP64F-LP64D-FPELIM-NEXT: li a1, 1
-; LP64-LP64F-LP64D-FPELIM-NEXT: slli a1, a1, 32
-; LP64-LP64F-LP64D-FPELIM-NEXT: addi a1, a1, -8
-; LP64-LP64F-LP64D-FPELIM-NEXT: and a0, a0, a1
+; LP64-LP64F-LP64D-FPELIM-NEXT: srliw a0, a0, 3
+; LP64-LP64F-LP64D-FPELIM-NEXT: slli a0, a0, 3
; LP64-LP64F-LP64D-FPELIM-NEXT: ld a0, 0(a0)
; LP64-LP64F-LP64D-FPELIM-NEXT: addi sp, sp, 80
; LP64-LP64F-LP64D-FPELIM-NEXT: ret
@@ -598,10 +596,8 @@ define i64 @va2(i8 *%fmt, ...) nounwind {
; LP64-LP64F-LP64D-WITHFP-NEXT: srli a1, a1, 32
; LP64-LP64F-LP64D-WITHFP-NEXT: addi a1, a1, 8
; LP64-LP64F-LP64D-WITHFP-NEXT: sd a1, -24(s0)
-; LP64-LP64F-LP64D-WITHFP-NEXT: li a1, 1
-; LP64-LP64F-LP64D-WITHFP-NEXT: slli a1, a1, 32
-; LP64-LP64F-LP64D-WITHFP-NEXT: addi a1, a1, -8
-; LP64-LP64F-LP64D-WITHFP-NEXT: and a0, a0, a1
+; LP64-LP64F-LP64D-WITHFP-NEXT: srliw a0, a0, 3
+; LP64-LP64F-LP64D-WITHFP-NEXT: slli a0, a0, 3
; LP64-LP64F-LP64D-WITHFP-NEXT: ld a0, 0(a0)
; LP64-LP64F-LP64D-WITHFP-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
; LP64-LP64F-LP64D-WITHFP-NEXT: ld s0, 16(sp) # 8-byte Folded Reload
@@ -892,10 +888,8 @@ define i64 @va3(i32 %a, i64 %b, ...) nounwind {
; LP64-LP64F-LP64D-FPELIM-NEXT: srli a2, a2, 32
; LP64-LP64F-LP64D-FPELIM-NEXT: addi a2, a2, 8
; LP64-LP64F-LP64D-FPELIM-NEXT: sd a2, 8(sp)
-; LP64-LP64F-LP64D-FPELIM-NEXT: li a2, 1
-; LP64-LP64F-LP64D-FPELIM-NEXT: slli a2, a2, 32
-; LP64-LP64F-LP64D-FPELIM-NEXT: addi a2, a2, -8
-; LP64-LP64F-LP64D-FPELIM-NEXT: and a0, a0, a2
+; LP64-LP64F-LP64D-FPELIM-NEXT: srliw a0, a0, 3
+; LP64-LP64F-LP64D-FPELIM-NEXT: slli a0, a0, 3
; LP64-LP64F-LP64D-FPELIM-NEXT: ld a0, 0(a0)
; LP64-LP64F-LP64D-FPELIM-NEXT: add a0, a1, a0
; LP64-LP64F-LP64D-FPELIM-NEXT: addi sp, sp, 64
@@ -921,10 +915,8 @@ define i64 @va3(i32 %a, i64 %b, ...) nounwind {
; LP64-LP64F-LP64D-WITHFP-NEXT: srli a2, a2, 32
; LP64-LP64F-LP64D-WITHFP-NEXT: addi a2, a2, 8
; LP64-LP64F-LP64D-WITHFP-NEXT: sd a2, -24(s0)
-; LP64-LP64F-LP64D-WITHFP-NEXT: li a2, 1
-; LP64-LP64F-LP64D-WITHFP-NEXT: slli a2, a2, 32
-; LP64-LP64F-LP64D-WITHFP-NEXT: addi a2, a2, -8
-; LP64-LP64F-LP64D-WITHFP-NEXT: and a0, a0, a2
+; LP64-LP64F-LP64D-WITHFP-NEXT: srliw a0, a0, 3
+; LP64-LP64F-LP64D-WITHFP-NEXT: slli a0, a0, 3
; LP64-LP64F-LP64D-WITHFP-NEXT: ld a0, 0(a0)
; LP64-LP64F-LP64D-WITHFP-NEXT: add a0, a1, a0
; LP64-LP64F-LP64D-WITHFP-NEXT: ld ra, 24(sp) # 8-byte Folded Reload