diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td --- a/llvm/lib/Target/RISCV/RISCV.td +++ b/llvm/lib/Target/RISCV/RISCV.td @@ -142,6 +142,8 @@ AssemblerPredicate<(any_of FeatureStdExtZbb, FeatureStdExtZbp), "'Zbb' (Base 'B' Instructions) or " "'Zbp' (Permutation 'B' Instructions)">; +def NotHasStdExtZbbOrZbp + : Predicate<"!Subtarget->hasStdExtZbb() && !Subtarget->hasStdExtZbp()">; def FeatureNoRVCHints : SubtargetFeature<"no-rvc-hints", "EnableRVCHintInstrs", "false", diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -1019,6 +1019,14 @@ return false; }]>; +def and_const_oneuse : PatFrag<(ops node:$A, node:$B), + (and node:$A, node:$B), [{ + if (auto *N1C = dyn_cast(N->getOperand(1))) + if (N1C->hasOneUse()) + return true; + return false; +}]>; + /// Simple arithmetic operations def : PatGprGpr; @@ -1034,6 +1042,14 @@ def : PatGprUimmLog2XLen; def : PatGprUimmLog2XLen; +// AND with mask exceeding simm12. +let Predicates = [NotHasStdExtZbbOrZbp, IsRV32] in +def : Pat<(i32 (and_const_oneuse GPR:$rs, 0xFFFF)), + (SRLI (SLLI $rs, 16), 16)>; +let Predicates = [NotHasStdExtZbbOrZbp, IsRV64] in +def : Pat<(i64 (and_const_oneuse GPR:$rs, 0xFFFF)), + (SRLI (SLLI $rs, 48), 48)>; + // Match both a plain shift and one where the shift amount is masked (this is // typically introduced when the legalizer promotes the shift amount and // zero-extends it). For RISC-V, the mask is unnecessary as shifts in the base diff --git a/llvm/test/CodeGen/RISCV/alu16.ll b/llvm/test/CodeGen/RISCV/alu16.ll --- a/llvm/test/CodeGen/RISCV/alu16.ll +++ b/llvm/test/CodeGen/RISCV/alu16.ll @@ -44,17 +44,15 @@ define i16 @sltiu(i16 %a) nounwind { ; RV32I-LABEL: sltiu: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: sltiu a0, a0, 3 ; RV32I-NEXT: ret ; ; RV64I-LABEL: sltiu: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: sltiu a0, a0, 3 ; RV64I-NEXT: ret %1 = icmp ult i16 %a, 3 @@ -274,17 +272,15 @@ define i16 @srl(i16 %a, i16 %b) nounwind { ; RV32I-LABEL: srl: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a2, 16 -; RV32I-NEXT: addi a2, a2, -1 -; RV32I-NEXT: and a0, a0, a2 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: srl a0, a0, a1 ; RV32I-NEXT: ret ; ; RV64I-LABEL: srl: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a2, 16 -; RV64I-NEXT: addiw a2, a2, -1 -; RV64I-NEXT: and a0, a0, a2 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: srl a0, a0, a1 ; RV64I-NEXT: ret %1 = lshr i16 %a, %b diff --git a/llvm/test/CodeGen/RISCV/atomic-rmw.ll b/llvm/test/CodeGen/RISCV/atomic-rmw.ll --- a/llvm/test/CodeGen/RISCV/atomic-rmw.ll +++ b/llvm/test/CodeGen/RISCV/atomic-rmw.ll @@ -6413,9 +6413,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoor.w a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6435,9 +6434,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoor.w a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6461,9 +6459,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoor.w.aq a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6483,9 +6480,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoor.w.aq a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6509,9 +6505,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoor.w.rl a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6531,9 +6526,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoor.w.rl a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6557,9 +6551,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoor.w.aqrl a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6579,9 +6572,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoor.w.aqrl a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6605,9 +6597,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoor.w.aqrl a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6627,9 +6618,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoor.w.aqrl a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6653,9 +6643,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoxor.w a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6675,9 +6664,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoxor.w a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6701,9 +6689,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoxor.w.aq a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6723,9 +6710,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoxor.w.aq a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6749,9 +6735,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoxor.w.rl a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6771,9 +6756,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoxor.w.rl a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6797,9 +6781,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoxor.w.aqrl a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6819,9 +6802,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoxor.w.aqrl a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -6845,9 +6827,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoxor.w.aqrl a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -6867,9 +6848,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoxor.w.aqrl a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 diff --git a/llvm/test/CodeGen/RISCV/atomic-signext.ll b/llvm/test/CodeGen/RISCV/atomic-signext.ll --- a/llvm/test/CodeGen/RISCV/atomic-signext.ll +++ b/llvm/test/CodeGen/RISCV/atomic-signext.ll @@ -1535,9 +1535,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoor.w a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -1561,9 +1560,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoor.w a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 @@ -1591,9 +1589,8 @@ ; RV32IA: # %bb.0: ; RV32IA-NEXT: andi a2, a0, -4 ; RV32IA-NEXT: slli a0, a0, 3 -; RV32IA-NEXT: lui a3, 16 -; RV32IA-NEXT: addi a3, a3, -1 -; RV32IA-NEXT: and a1, a1, a3 +; RV32IA-NEXT: slli a1, a1, 16 +; RV32IA-NEXT: srli a1, a1, 16 ; RV32IA-NEXT: sll a1, a1, a0 ; RV32IA-NEXT: amoxor.w a1, a1, (a2) ; RV32IA-NEXT: srl a0, a1, a0 @@ -1617,9 +1614,8 @@ ; RV64IA: # %bb.0: ; RV64IA-NEXT: andi a2, a0, -4 ; RV64IA-NEXT: slliw a0, a0, 3 -; RV64IA-NEXT: lui a3, 16 -; RV64IA-NEXT: addiw a3, a3, -1 -; RV64IA-NEXT: and a1, a1, a3 +; RV64IA-NEXT: slli a1, a1, 48 +; RV64IA-NEXT: srli a1, a1, 48 ; RV64IA-NEXT: sllw a1, a1, a0 ; RV64IA-NEXT: amoxor.w a1, a1, (a2) ; RV64IA-NEXT: srlw a0, a1, a0 diff --git a/llvm/test/CodeGen/RISCV/bswap-ctlz-cttz-ctpop.ll b/llvm/test/CodeGen/RISCV/bswap-ctlz-cttz-ctpop.ll --- a/llvm/test/CodeGen/RISCV/bswap-ctlz-cttz-ctpop.ll +++ b/llvm/test/CodeGen/RISCV/bswap-ctlz-cttz-ctpop.ll @@ -186,9 +186,8 @@ define i16 @test_cttz_i16(i16 %a) nounwind { ; RV32I-LABEL: test_cttz_i16: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a1, a0, a1 +; RV32I-NEXT: slli a1, a0, 16 +; RV32I-NEXT: srli a1, a1, 16 ; RV32I-NEXT: beqz a1, .LBB4_2 ; RV32I-NEXT: # %bb.1: # %cond.false ; RV32I-NEXT: addi a1, a0, -1 @@ -223,9 +222,8 @@ ; ; RV64I-LABEL: test_cttz_i16: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a1, a0, a1 +; RV64I-NEXT: slli a1, a0, 48 +; RV64I-NEXT: srli a1, a1, 48 ; RV64I-NEXT: beqz a1, .LBB4_2 ; RV64I-NEXT: # %bb.1: # %cond.false ; RV64I-NEXT: addi a1, a0, -1 diff --git a/llvm/test/CodeGen/RISCV/calling-conv-half.ll b/llvm/test/CodeGen/RISCV/calling-conv-half.ll --- a/llvm/test/CodeGen/RISCV/calling-conv-half.ll +++ b/llvm/test/CodeGen/RISCV/calling-conv-half.ll @@ -19,9 +19,8 @@ ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s0, 8(sp) # 4-byte Folded Spill ; RV32I-NEXT: mv s0, a0 -; RV32I-NEXT: lui a0, 16 -; RV32I-NEXT: addi a0, a0, -1 -; RV32I-NEXT: and a0, a1, a0 +; RV32I-NEXT: slli a0, a1, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixsfsi@plt ; RV32I-NEXT: add a0, s0, a0 @@ -36,9 +35,8 @@ ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s0, 0(sp) # 8-byte Folded Spill ; RV64I-NEXT: mv s0, a0 -; RV64I-NEXT: lui a0, 16 -; RV64I-NEXT: addiw a0, a0, -1 -; RV64I-NEXT: and a0, a1, a0 +; RV64I-NEXT: slli a0, a1, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixsfdi@plt ; RV64I-NEXT: addw a0, s0, a0 @@ -586,9 +584,8 @@ ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill ; RV32I-NEXT: call callee_half_ret@plt -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixsfsi@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -600,9 +597,8 @@ ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: call callee_half_ret@plt -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixsfdi@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload diff --git a/llvm/test/CodeGen/RISCV/calling-conv-ilp32-ilp32f-ilp32d-common.ll b/llvm/test/CodeGen/RISCV/calling-conv-ilp32-ilp32f-ilp32d-common.ll --- a/llvm/test/CodeGen/RISCV/calling-conv-ilp32-ilp32f-ilp32d-common.ll +++ b/llvm/test/CodeGen/RISCV/calling-conv-ilp32-ilp32f-ilp32d-common.ll @@ -84,11 +84,10 @@ ; RV32I-FPELIM: # %bb.0: ; RV32I-FPELIM-NEXT: lw t0, 4(sp) ; RV32I-FPELIM-NEXT: lw t1, 0(sp) -; RV32I-FPELIM-NEXT: andi t2, a0, 255 -; RV32I-FPELIM-NEXT: lui a0, 16 -; RV32I-FPELIM-NEXT: addi a0, a0, -1 -; RV32I-FPELIM-NEXT: and a0, a1, a0 -; RV32I-FPELIM-NEXT: add a0, t2, a0 +; RV32I-FPELIM-NEXT: andi a0, a0, 255 +; RV32I-FPELIM-NEXT: slli a1, a1, 16 +; RV32I-FPELIM-NEXT: srli a1, a1, 16 +; RV32I-FPELIM-NEXT: add a0, a0, a1 ; RV32I-FPELIM-NEXT: add a0, a0, a2 ; RV32I-FPELIM-NEXT: xor a1, a4, t1 ; RV32I-FPELIM-NEXT: xor a2, a3, a7 @@ -108,11 +107,10 @@ ; RV32I-WITHFP-NEXT: addi s0, sp, 16 ; RV32I-WITHFP-NEXT: lw t0, 4(s0) ; RV32I-WITHFP-NEXT: lw t1, 0(s0) -; RV32I-WITHFP-NEXT: andi t2, a0, 255 -; RV32I-WITHFP-NEXT: lui a0, 16 -; RV32I-WITHFP-NEXT: addi a0, a0, -1 -; RV32I-WITHFP-NEXT: and a0, a1, a0 -; RV32I-WITHFP-NEXT: add a0, t2, a0 +; RV32I-WITHFP-NEXT: andi a0, a0, 255 +; RV32I-WITHFP-NEXT: slli a1, a1, 16 +; RV32I-WITHFP-NEXT: srli a1, a1, 16 +; RV32I-WITHFP-NEXT: add a0, a0, a1 ; RV32I-WITHFP-NEXT: add a0, a0, a2 ; RV32I-WITHFP-NEXT: xor a1, a4, t1 ; RV32I-WITHFP-NEXT: xor a2, a3, a7 diff --git a/llvm/test/CodeGen/RISCV/calling-conv-lp64-lp64f-lp64d-common.ll b/llvm/test/CodeGen/RISCV/calling-conv-lp64-lp64f-lp64d-common.ll --- a/llvm/test/CodeGen/RISCV/calling-conv-lp64-lp64f-lp64d-common.ll +++ b/llvm/test/CodeGen/RISCV/calling-conv-lp64-lp64f-lp64d-common.ll @@ -50,11 +50,10 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: lw t0, 8(sp) ; RV64I-NEXT: ld t1, 0(sp) -; RV64I-NEXT: andi t2, a0, 255 -; RV64I-NEXT: lui a0, 16 -; RV64I-NEXT: addiw a0, a0, -1 -; RV64I-NEXT: and a0, a1, a0 -; RV64I-NEXT: addw a0, t2, a0 +; RV64I-NEXT: andi a0, a0, 255 +; RV64I-NEXT: slli a1, a1, 48 +; RV64I-NEXT: srli a1, a1, 48 +; RV64I-NEXT: addw a0, a0, a1 ; RV64I-NEXT: addw a0, a0, a2 ; RV64I-NEXT: xor a1, a4, t1 ; RV64I-NEXT: xor a2, a3, a7 diff --git a/llvm/test/CodeGen/RISCV/div.ll b/llvm/test/CodeGen/RISCV/div.ll --- a/llvm/test/CodeGen/RISCV/div.ll +++ b/llvm/test/CodeGen/RISCV/div.ll @@ -481,9 +481,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: li a1, 5 ; RV32I-NEXT: call __udivsi3@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -502,9 +501,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: li a1, 5 ; RV64I-NEXT: call __udivdi3@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -556,9 +554,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a1, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a1, a0, 16 ; RV32I-NEXT: li a0, 10 ; RV32I-NEXT: call __udivsi3@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -567,9 +564,8 @@ ; ; RV32IM-LABEL: udiv16_constant_lhs: ; RV32IM: # %bb.0: -; RV32IM-NEXT: lui a1, 16 -; RV32IM-NEXT: addi a1, a1, -1 -; RV32IM-NEXT: and a0, a0, a1 +; RV32IM-NEXT: slli a0, a0, 16 +; RV32IM-NEXT: srli a0, a0, 16 ; RV32IM-NEXT: li a1, 10 ; RV32IM-NEXT: divu a0, a1, a0 ; RV32IM-NEXT: ret @@ -578,9 +574,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a1, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a1, a0, 48 ; RV64I-NEXT: li a0, 10 ; RV64I-NEXT: call __udivdi3@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -589,9 +584,8 @@ ; ; RV64IM-LABEL: udiv16_constant_lhs: ; RV64IM: # %bb.0: -; RV64IM-NEXT: lui a1, 16 -; RV64IM-NEXT: addiw a1, a1, -1 -; RV64IM-NEXT: and a0, a0, a1 +; RV64IM-NEXT: slli a0, a0, 48 +; RV64IM-NEXT: srli a0, a0, 48 ; RV64IM-NEXT: li a1, 10 ; RV64IM-NEXT: divuw a0, a1, a0 ; RV64IM-NEXT: ret diff --git a/llvm/test/CodeGen/RISCV/half-arith.ll b/llvm/test/CodeGen/RISCV/half-arith.ll --- a/llvm/test/CodeGen/RISCV/half-arith.ll +++ b/llvm/test/CodeGen/RISCV/half-arith.ll @@ -294,9 +294,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call sqrtf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -308,9 +307,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call sqrtf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt diff --git a/llvm/test/CodeGen/RISCV/half-convert-strict.ll b/llvm/test/CodeGen/RISCV/half-convert-strict.ll --- a/llvm/test/CodeGen/RISCV/half-convert-strict.ll +++ b/llvm/test/CodeGen/RISCV/half-convert-strict.ll @@ -291,33 +291,29 @@ define half @fcvt_h_ui(i16 %a) nounwind strictfp { ; RV32IZFH-LABEL: fcvt_h_ui: ; RV32IZFH: # %bb.0: -; RV32IZFH-NEXT: lui a1, 16 -; RV32IZFH-NEXT: addi a1, a1, -1 -; RV32IZFH-NEXT: and a0, a0, a1 +; RV32IZFH-NEXT: slli a0, a0, 16 +; RV32IZFH-NEXT: srli a0, a0, 16 ; RV32IZFH-NEXT: fcvt.h.wu fa0, a0 ; RV32IZFH-NEXT: ret ; ; RV64IZFH-LABEL: fcvt_h_ui: ; RV64IZFH: # %bb.0: -; RV64IZFH-NEXT: lui a1, 16 -; RV64IZFH-NEXT: addiw a1, a1, -1 -; RV64IZFH-NEXT: and a0, a0, a1 +; RV64IZFH-NEXT: slli a0, a0, 48 +; RV64IZFH-NEXT: srli a0, a0, 48 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0 ; RV64IZFH-NEXT: ret ; ; RV32IDZFH-LABEL: fcvt_h_ui: ; RV32IDZFH: # %bb.0: -; RV32IDZFH-NEXT: lui a1, 16 -; RV32IDZFH-NEXT: addi a1, a1, -1 -; RV32IDZFH-NEXT: and a0, a0, a1 +; RV32IDZFH-NEXT: slli a0, a0, 16 +; RV32IDZFH-NEXT: srli a0, a0, 16 ; RV32IDZFH-NEXT: fcvt.h.wu fa0, a0 ; RV32IDZFH-NEXT: ret ; ; RV64IDZFH-LABEL: fcvt_h_ui: ; RV64IDZFH: # %bb.0: -; RV64IDZFH-NEXT: lui a1, 16 -; RV64IDZFH-NEXT: addiw a1, a1, -1 -; RV64IDZFH-NEXT: and a0, a0, a1 +; RV64IDZFH-NEXT: slli a0, a0, 48 +; RV64IDZFH-NEXT: srli a0, a0, 48 ; RV64IDZFH-NEXT: fcvt.h.wu fa0, a0 ; RV64IDZFH-NEXT: ret %1 = call half @llvm.experimental.constrained.uitofp.f16.i16(i16 %a, metadata !"round.dynamic", metadata !"fpexcept.strict") strictfp diff --git a/llvm/test/CodeGen/RISCV/half-convert.ll b/llvm/test/CodeGen/RISCV/half-convert.ll --- a/llvm/test/CodeGen/RISCV/half-convert.ll +++ b/llvm/test/CodeGen/RISCV/half-convert.ll @@ -37,9 +37,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixsfsi@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -50,9 +49,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixsfdi@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -143,9 +141,8 @@ ; RV32I-NEXT: sw s1, 20(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s2, 16(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: mv s0, a0 ; RV32I-NEXT: lui a1, 815104 @@ -192,9 +189,8 @@ ; RV64I-NEXT: sd s1, 24(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s2, 16(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s3, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: mv s0, a0 ; RV64I-NEXT: lui a1, 815104 @@ -263,9 +259,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixunssfsi@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -276,9 +271,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixunssfdi@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -443,9 +437,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixsfsi@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -456,9 +449,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixsfdi@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -522,9 +514,8 @@ ; RV32I-NEXT: sw s2, 16(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: mv s0, a0 ; RV32I-NEXT: lui a1, 847872 @@ -573,9 +564,8 @@ ; RV64I-NEXT: sd s2, 16(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s3, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s4, 0(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: mv s0, a0 ; RV64I-NEXT: lui a1, 847872 @@ -645,9 +635,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixunssfsi@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -658,9 +647,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixunssfdi@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -719,9 +707,8 @@ ; RV32I-NEXT: .cfi_def_cfa_offset 16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill ; RV32I-NEXT: .cfi_offset ra, -4 -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixunssfsi@plt ; RV32I-NEXT: mv a1, a0 @@ -740,9 +727,8 @@ ; RV64I-NEXT: .cfi_def_cfa_offset 16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: .cfi_offset ra, -8 -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixunssfdi@plt ; RV64I-NEXT: mv a1, a0 @@ -812,9 +798,8 @@ ; RV32I-NEXT: sw s0, 8(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s1, 4(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s2, 0(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: mv s0, a0 ; RV32I-NEXT: li a1, 0 @@ -851,9 +836,8 @@ ; RV64I-NEXT: sd s0, 16(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s1, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s2, 0(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: mv s0, a0 ; RV64I-NEXT: li a1, 0 @@ -921,9 +905,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixsfdi@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -934,9 +917,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixsfdi@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -1092,9 +1074,8 @@ ; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s5, 4(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s6, 0(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: mv s0, a0 ; RV32I-NEXT: lui a1, 913408 @@ -1172,9 +1153,8 @@ ; RV64I-NEXT: sd s2, 16(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s3, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s4, 0(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: mv s0, a0 ; RV64I-NEXT: lui a1, 913408 @@ -1254,9 +1234,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __fixunssfdi@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -1267,9 +1246,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call __fixunssfdi@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -1398,9 +1376,8 @@ ; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s5, 4(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: mv s0, a0 ; RV32I-NEXT: li a1, 0 @@ -1459,9 +1436,8 @@ ; RV64I-NEXT: sd s0, 16(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s1, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s2, 0(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: mv s0, a0 ; RV64I-NEXT: li a1, 0 @@ -1599,33 +1575,29 @@ define half @fcvt_h_ui(i16 %a) nounwind { ; RV32IZFH-LABEL: fcvt_h_ui: ; RV32IZFH: # %bb.0: -; RV32IZFH-NEXT: lui a1, 16 -; RV32IZFH-NEXT: addi a1, a1, -1 -; RV32IZFH-NEXT: and a0, a0, a1 +; RV32IZFH-NEXT: slli a0, a0, 16 +; RV32IZFH-NEXT: srli a0, a0, 16 ; RV32IZFH-NEXT: fcvt.h.wu fa0, a0 ; RV32IZFH-NEXT: ret ; ; RV64IZFH-LABEL: fcvt_h_ui: ; RV64IZFH: # %bb.0: -; RV64IZFH-NEXT: lui a1, 16 -; RV64IZFH-NEXT: addiw a1, a1, -1 -; RV64IZFH-NEXT: and a0, a0, a1 +; RV64IZFH-NEXT: slli a0, a0, 48 +; RV64IZFH-NEXT: srli a0, a0, 48 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0 ; RV64IZFH-NEXT: ret ; ; RV32IDZFH-LABEL: fcvt_h_ui: ; RV32IDZFH: # %bb.0: -; RV32IDZFH-NEXT: lui a1, 16 -; RV32IDZFH-NEXT: addi a1, a1, -1 -; RV32IDZFH-NEXT: and a0, a0, a1 +; RV32IDZFH-NEXT: slli a0, a0, 16 +; RV32IDZFH-NEXT: srli a0, a0, 16 ; RV32IDZFH-NEXT: fcvt.h.wu fa0, a0 ; RV32IDZFH-NEXT: ret ; ; RV64IDZFH-LABEL: fcvt_h_ui: ; RV64IDZFH: # %bb.0: -; RV64IDZFH-NEXT: lui a1, 16 -; RV64IDZFH-NEXT: addiw a1, a1, -1 -; RV64IDZFH-NEXT: and a0, a0, a1 +; RV64IDZFH-NEXT: slli a0, a0, 48 +; RV64IDZFH-NEXT: srli a0, a0, 48 ; RV64IDZFH-NEXT: fcvt.h.wu fa0, a0 ; RV64IDZFH-NEXT: ret ; @@ -1633,9 +1605,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __floatunsisf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -1646,9 +1617,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __floatunsisf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -2065,9 +2035,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload ; RV32I-NEXT: addi sp, sp, 16 @@ -2077,9 +2046,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload ; RV64I-NEXT: addi sp, sp, 16 @@ -2173,9 +2141,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call __extendsfdf2@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -2186,9 +2153,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: slli a0, a0, 32 ; RV64I-NEXT: srli a0, a0, 32 diff --git a/llvm/test/CodeGen/RISCV/half-intrinsics.ll b/llvm/test/CodeGen/RISCV/half-intrinsics.ll --- a/llvm/test/CodeGen/RISCV/half-intrinsics.ll +++ b/llvm/test/CodeGen/RISCV/half-intrinsics.ll @@ -45,9 +45,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call sqrtf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -59,9 +58,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call sqrtf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -127,9 +125,8 @@ ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill ; RV32I-NEXT: sw s0, 8(sp) # 4-byte Folded Spill ; RV32I-NEXT: mv s0, a1 -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: mv a1, s0 ; RV32I-NEXT: call __powisf2@plt @@ -145,9 +142,8 @@ ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill ; RV64I-NEXT: sd s0, 0(sp) # 8-byte Folded Spill ; RV64I-NEXT: mv s0, a1 -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: sext.w a1, s0 ; RV64I-NEXT: call __powisf2@plt @@ -211,9 +207,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call sinf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -225,9 +220,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call sinf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -289,9 +283,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call cosf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -303,9 +296,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call cosf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -630,9 +622,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call expf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -644,9 +635,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call expf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -708,9 +698,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call exp2f@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -722,9 +711,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call exp2f@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -786,9 +774,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call logf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -800,9 +787,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call logf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -864,9 +850,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call log10f@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -878,9 +863,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call log10f@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -942,9 +926,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call log2f@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -956,9 +939,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call log2f@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -1473,9 +1455,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call floorf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -1487,9 +1468,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call floorf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -1551,9 +1531,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call ceilf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -1565,9 +1544,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call ceilf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -1629,9 +1607,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call truncf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -1643,9 +1620,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call truncf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -1707,9 +1683,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call rintf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -1721,9 +1696,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call rintf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -1785,9 +1759,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call nearbyintf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -1799,9 +1772,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call nearbyintf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -1863,9 +1835,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call roundf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -1877,9 +1848,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call roundf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt @@ -1941,9 +1911,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: call __gnu_h2f_ieee@plt ; RV32I-NEXT: call roundevenf@plt ; RV32I-NEXT: call __gnu_f2h_ieee@plt @@ -1955,9 +1924,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: call __gnu_h2f_ieee@plt ; RV64I-NEXT: call roundevenf@plt ; RV64I-NEXT: call __gnu_f2h_ieee@plt diff --git a/llvm/test/CodeGen/RISCV/rem.ll b/llvm/test/CodeGen/RISCV/rem.ll --- a/llvm/test/CodeGen/RISCV/rem.ll +++ b/llvm/test/CodeGen/RISCV/rem.ll @@ -632,9 +632,8 @@ ; RV32I: # %bb.0: ; RV32I-NEXT: addi sp, sp, -16 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a1, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a1, a0, 16 ; RV32I-NEXT: li a0, 10 ; RV32I-NEXT: call __umodsi3@plt ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload @@ -643,9 +642,8 @@ ; ; RV32IM-LABEL: urem16_constant_lhs: ; RV32IM: # %bb.0: -; RV32IM-NEXT: lui a1, 16 -; RV32IM-NEXT: addi a1, a1, -1 -; RV32IM-NEXT: and a0, a0, a1 +; RV32IM-NEXT: slli a0, a0, 16 +; RV32IM-NEXT: srli a0, a0, 16 ; RV32IM-NEXT: li a1, 10 ; RV32IM-NEXT: remu a0, a1, a0 ; RV32IM-NEXT: ret @@ -654,9 +652,8 @@ ; RV64I: # %bb.0: ; RV64I-NEXT: addi sp, sp, -16 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a1, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a1, a0, 48 ; RV64I-NEXT: li a0, 10 ; RV64I-NEXT: call __umoddi3@plt ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload @@ -665,9 +662,8 @@ ; ; RV64IM-LABEL: urem16_constant_lhs: ; RV64IM: # %bb.0: -; RV64IM-NEXT: lui a1, 16 -; RV64IM-NEXT: addiw a1, a1, -1 -; RV64IM-NEXT: and a0, a0, a1 +; RV64IM-NEXT: slli a0, a0, 48 +; RV64IM-NEXT: srli a0, a0, 48 ; RV64IM-NEXT: li a1, 10 ; RV64IM-NEXT: remuw a0, a1, a0 ; RV64IM-NEXT: ret diff --git a/llvm/test/CodeGen/RISCV/rv32zbb.ll b/llvm/test/CodeGen/RISCV/rv32zbb.ll --- a/llvm/test/CodeGen/RISCV/rv32zbb.ll +++ b/llvm/test/CodeGen/RISCV/rv32zbb.ll @@ -776,9 +776,8 @@ define i32 @zexth_i32(i32 %a) nounwind { ; RV32I-LABEL: zexth_i32: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: ret ; ; RV32ZBB-LABEL: zexth_i32: @@ -792,9 +791,8 @@ define i64 @zexth_i64(i64 %a) nounwind { ; RV32I-LABEL: zexth_i64: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: li a1, 0 ; RV32I-NEXT: ret ; diff --git a/llvm/test/CodeGen/RISCV/rv32zbp.ll b/llvm/test/CodeGen/RISCV/rv32zbp.ll --- a/llvm/test/CodeGen/RISCV/rv32zbp.ll +++ b/llvm/test/CodeGen/RISCV/rv32zbp.ll @@ -2074,9 +2074,8 @@ ; RV32I-NEXT: srli a1, a0, 8 ; RV32I-NEXT: slli a0, a0, 8 ; RV32I-NEXT: or a0, a0, a1 -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: ret ; ; RV32ZBP-LABEL: bswap_i16: @@ -2837,9 +2836,8 @@ define i32 @pack_i32(i32 %a, i32 %b) nounwind { ; RV32I-LABEL: pack_i32: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a2, 16 -; RV32I-NEXT: addi a2, a2, -1 -; RV32I-NEXT: and a0, a0, a2 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: slli a1, a1, 16 ; RV32I-NEXT: or a0, a1, a0 ; RV32I-NEXT: ret @@ -2962,9 +2960,8 @@ define i32 @zexth_i32(i32 %a) nounwind { ; RV32I-LABEL: zexth_i32: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: ret ; ; RV32ZBP-LABEL: zexth_i32: @@ -2978,9 +2975,8 @@ define i64 @zexth_i64(i64 %a) nounwind { ; RV32I-LABEL: zexth_i64: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: li a1, 0 ; RV32I-NEXT: ret ; diff --git a/llvm/test/CodeGen/RISCV/rv64zbb.ll b/llvm/test/CodeGen/RISCV/rv64zbb.ll --- a/llvm/test/CodeGen/RISCV/rv64zbb.ll +++ b/llvm/test/CodeGen/RISCV/rv64zbb.ll @@ -979,9 +979,8 @@ define i32 @zexth_i32(i32 %a) nounwind { ; RV64I-LABEL: zexth_i32: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: ret ; ; RV64ZBB-LABEL: zexth_i32: @@ -995,9 +994,8 @@ define i64 @zexth_i64(i64 %a) nounwind { ; RV64I-LABEL: zexth_i64: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: ret ; ; RV64ZBB-LABEL: zexth_i64: diff --git a/llvm/test/CodeGen/RISCV/rv64zbp.ll b/llvm/test/CodeGen/RISCV/rv64zbp.ll --- a/llvm/test/CodeGen/RISCV/rv64zbp.ll +++ b/llvm/test/CodeGen/RISCV/rv64zbp.ll @@ -1955,9 +1955,8 @@ ; RV64I-NEXT: srli a1, a0, 8 ; RV64I-NEXT: slli a0, a0, 8 ; RV64I-NEXT: or a0, a0, a1 -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: ret ; ; RV64ZBP-LABEL: bswap_i16: @@ -2787,9 +2786,8 @@ define signext i32 @pack_i32(i32 signext %a, i32 signext %b) nounwind { ; RV64I-LABEL: pack_i32: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a2, 16 -; RV64I-NEXT: addiw a2, a2, -1 -; RV64I-NEXT: and a0, a0, a2 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: slliw a1, a1, 16 ; RV64I-NEXT: or a0, a1, a0 ; RV64I-NEXT: ret @@ -2905,9 +2903,8 @@ define i32 @zexth_i32(i32 %a) nounwind { ; RV64I-LABEL: zexth_i32: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: ret ; ; RV64ZBP-LABEL: zexth_i32: @@ -2921,9 +2918,8 @@ define i64 @zexth_i64(i64 %a) nounwind { ; RV64I-LABEL: zexth_i64: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: ret ; ; RV64ZBP-LABEL: zexth_i64: diff --git a/llvm/test/CodeGen/RISCV/rv64zfh-half-convert.ll b/llvm/test/CodeGen/RISCV/rv64zfh-half-convert.ll --- a/llvm/test/CodeGen/RISCV/rv64zfh-half-convert.ll +++ b/llvm/test/CodeGen/RISCV/rv64zfh-half-convert.ll @@ -92,9 +92,8 @@ ; RV64IZFH: # %bb.0: ; RV64IZFH-NEXT: fadd.h ft0, fa0, fa1 ; RV64IZFH-NEXT: fmv.x.h a0, ft0 -; RV64IZFH-NEXT: lui a1, 16 -; RV64IZFH-NEXT: addiw a1, a1, -1 -; RV64IZFH-NEXT: and a0, a0, a1 +; RV64IZFH-NEXT: slli a0, a0, 48 +; RV64IZFH-NEXT: srli a0, a0, 48 ; RV64IZFH-NEXT: ret %1 = fadd half %a, %b %2 = bitcast half %1 to i16 diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-int-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-int-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-int-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-int-vp.ll @@ -268,9 +268,8 @@ define signext i16 @vpreduce_umax_v2i16(i16 signext %s, <2 x i16> %v, <2 x i1> %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umax_v2i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -280,9 +279,8 @@ ; ; RV64-LABEL: vpreduce_umax_v2i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -313,9 +311,8 @@ define signext i16 @vpreduce_umin_v2i16(i16 signext %s, <2 x i16> %v, <2 x i1> %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umin_v2i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -325,9 +322,8 @@ ; ; RV64-LABEL: vpreduce_umin_v2i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -418,9 +414,8 @@ define signext i16 @vpreduce_umax_v4i16(i16 signext %s, <4 x i16> %v, <4 x i1> %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umax_v4i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf2, tu, mu @@ -430,9 +425,8 @@ ; ; RV64-LABEL: vpreduce_umax_v4i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf2, tu, mu @@ -463,9 +457,8 @@ define signext i16 @vpreduce_umin_v4i16(i16 signext %s, <4 x i16> %v, <4 x i1> %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umin_v4i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf2, tu, mu @@ -475,9 +468,8 @@ ; ; RV64-LABEL: vpreduce_umin_v4i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf2, tu, mu diff --git a/llvm/test/CodeGen/RISCV/rvv/vreductions-int-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vreductions-int-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vreductions-int-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vreductions-int-vp.ll @@ -390,9 +390,8 @@ define signext i16 @vpreduce_umax_nxv1i16(i16 signext %s, %v, %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umax_nxv1i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -402,9 +401,8 @@ ; ; RV64-LABEL: vpreduce_umax_nxv1i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -435,9 +433,8 @@ define signext i16 @vpreduce_umin_nxv1i16(i16 signext %s, %v, %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umin_nxv1i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -447,9 +444,8 @@ ; ; RV64-LABEL: vpreduce_umin_nxv1i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf4, tu, mu @@ -540,9 +536,8 @@ define signext i16 @vpreduce_umax_nxv2i16(i16 signext %s, %v, %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umax_nxv2i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf2, tu, mu @@ -552,9 +547,8 @@ ; ; RV64-LABEL: vpreduce_umax_nxv2i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf2, tu, mu @@ -585,9 +579,8 @@ define signext i16 @vpreduce_umin_nxv2i16(i16 signext %s, %v, %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umin_nxv2i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, mf2, tu, mu @@ -597,9 +590,8 @@ ; ; RV64-LABEL: vpreduce_umin_nxv2i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, mf2, tu, mu @@ -690,9 +682,8 @@ define signext i16 @vpreduce_umax_nxv4i16(i16 signext %s, %v, %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umax_nxv4i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, m1, tu, mu @@ -702,9 +693,8 @@ ; ; RV64-LABEL: vpreduce_umax_nxv4i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, m1, tu, mu @@ -735,9 +725,8 @@ define signext i16 @vpreduce_umin_nxv4i16(i16 signext %s, %v, %m, i32 zeroext %evl) { ; RV32-LABEL: vpreduce_umin_nxv4i16: ; RV32: # %bb.0: -; RV32-NEXT: lui a2, 16 -; RV32-NEXT: addi a2, a2, -1 -; RV32-NEXT: and a0, a0, a2 +; RV32-NEXT: slli a0, a0, 16 +; RV32-NEXT: srli a0, a0, 16 ; RV32-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV32-NEXT: vmv.v.x v9, a0 ; RV32-NEXT: vsetvli zero, a1, e16, m1, tu, mu @@ -747,9 +736,8 @@ ; ; RV64-LABEL: vpreduce_umin_nxv4i16: ; RV64: # %bb.0: -; RV64-NEXT: lui a2, 16 -; RV64-NEXT: addiw a2, a2, -1 -; RV64-NEXT: and a0, a0, a2 +; RV64-NEXT: slli a0, a0, 48 +; RV64-NEXT: srli a0, a0, 48 ; RV64-NEXT: vsetivli zero, 1, e16, m1, ta, mu ; RV64-NEXT: vmv.v.x v9, a0 ; RV64-NEXT: vsetvli zero, a1, e16, m1, tu, mu diff --git a/llvm/test/CodeGen/RISCV/sext-zext-trunc.ll b/llvm/test/CodeGen/RISCV/sext-zext-trunc.ll --- a/llvm/test/CodeGen/RISCV/sext-zext-trunc.ll +++ b/llvm/test/CodeGen/RISCV/sext-zext-trunc.ll @@ -268,16 +268,14 @@ define i32 @zext_i16_to_i32(i16 %a) nounwind { ; RV32I-LABEL: zext_i16_to_i32: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: ret ; ; RV64I-LABEL: zext_i16_to_i32: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: ret %1 = zext i16 %a to i32 ret i32 %1 @@ -286,17 +284,15 @@ define i64 @zext_i16_to_i64(i16 %a) nounwind { ; RV32I-LABEL: zext_i16_to_i64: ; RV32I: # %bb.0: -; RV32I-NEXT: lui a1, 16 -; RV32I-NEXT: addi a1, a1, -1 -; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: slli a0, a0, 16 +; RV32I-NEXT: srli a0, a0, 16 ; RV32I-NEXT: li a1, 0 ; RV32I-NEXT: ret ; ; RV64I-LABEL: zext_i16_to_i64: ; RV64I: # %bb.0: -; RV64I-NEXT: lui a1, 16 -; RV64I-NEXT: addiw a1, a1, -1 -; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: slli a0, a0, 48 +; RV64I-NEXT: srli a0, a0, 48 ; RV64I-NEXT: ret %1 = zext i16 %a to i64 ret i64 %1