[PATCH] D111532: [RISCV] Optimize immediate materialisation with BCLRI
Ben Shi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 11 03:48:48 PDT 2021
benshi001 updated this revision to Diff 378617.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111532/new/
https://reviews.llvm.org/D111532
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
llvm/test/CodeGen/RISCV/imm.ll
Index: llvm/test/CodeGen/RISCV/imm.ll
===================================================================
--- llvm/test/CodeGen/RISCV/imm.ll
+++ llvm/test/CodeGen/RISCV/imm.ll
@@ -804,10 +804,9 @@
;
; RV64IB-LABEL: imm_neg_2863311530:
; RV64IB: # %bb.0:
-; RV64IB-NEXT: lui a0, 1048405
-; RV64IB-NEXT: addiw a0, a0, 1365
-; RV64IB-NEXT: slli a0, a0, 12
-; RV64IB-NEXT: addi a0, a0, 1366
+; RV64IB-NEXT: lui a0, 873813
+; RV64IB-NEXT: addiw a0, a0, 1366
+; RV64IB-NEXT: bclri a0, a0, 31
; RV64IB-NEXT: ret
ret i64 -2863311530 ; #0xffffffff55555556
}
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
@@ -182,6 +182,22 @@
}
}
+ // Optimize for values in range 0xffffffff 7fffffff ~ 0xffffffff 00000000.
+ // First call generateInstSeqImpl with Val+0x80000000 (which is an int32),
+ // then emit (BCLRI r, 31).
+ if (Res.size() > 2 && ActiveFeatures[RISCV::FeatureStdExtZbs]) {
+ assert(ActiveFeatures[RISCV::Feature64Bit] &&
+ "Expected RV32 to only need 2 instructions");
+ int64_t NewVal = Val + 0x80000000;
+ if (NewVal < 0 && isInt<32>(NewVal)) {
+ RISCVMatInt::InstSeq TmpSeq;
+ generateInstSeqImpl(NewVal, ActiveFeatures, TmpSeq);
+ TmpSeq.push_back(RISCVMatInt::Inst(RISCV::BCLRI, 31));
+ if (TmpSeq.size() < Res.size())
+ return TmpSeq;
+ }
+ }
+
return Res;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111532.378617.patch
Type: text/x-patch
Size: 1560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211011/6a5e081a/attachment.bin>
More information about the llvm-commits
mailing list