[PATCH] D156442: [RISCV][Backend] Zext flag conversion in RISC-V Backend
Panagiotis K via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 27 10:08:35 PDT 2023
karouzakisp updated this revision to Diff 544835.
karouzakisp added a comment.
Added -U999999 in
git show
to make possible the reviewing via the web interface.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156442/new/
https://reviews.llvm.org/D156442
Files:
llvm/lib/Target/RISCV/RISCVCodeGenPrepare.cpp
Index: llvm/lib/Target/RISCV/RISCVCodeGenPrepare.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVCodeGenPrepare.cpp
+++ llvm/lib/Target/RISCV/RISCVCodeGenPrepare.cpp
@@ -29,6 +29,8 @@
#define PASS_NAME "RISCV CodeGenPrepare"
STATISTIC(NumZExtToSExt, "Number of SExt instructions converted to ZExt");
+STATISTIC(NumZExtToSExtNonNeg,
+ "Number of SExt non negative value instructions converted to ZExt");
namespace {
@@ -84,6 +86,30 @@
return true;
}
+ // Look for an non negative zext(value) and replace it with sext.
+ if (isKnownNonNegative(Src, *DL)) {
+ auto SExt = new SExtInst(Src, ZExt.getType(), "", &ZExt);
+ SExt->takeName(&ZExt);
+ SExt->setDebugLoc(ZExt.getDebugLoc());
+
+ ZExt.replaceAllUsesWith(SExt);
+ ZExt.eraseFromParent();
+ ++NumZExtToSExtNonNeg;
+ return true;
+ }
+
+ // Look for zext instructions that can be sext.
+ if (ZExt.wasSext()) {
+ auto SExt = new SExtInst(Src, ZExt.getType(), "", &ZExt);
+ SExt->takeName(&ZExt);
+ SExt->setDebugLoc(ZExt.getDebugLoc());
+
+ ZExt.replaceAllUsesWith(SExt);
+ ZExt.eraseFromParent();
+ ++NumZExtToSExtNonNeg;
+ return true;
+ }
+
// Convert (zext (abs(i32 X, i1 1))) -> (sext (abs(i32 X, i1 1))). If abs of
// INT_MIN is poison, the sign bit is zero.
using namespace PatternMatch;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156442.544835.patch
Type: text/x-patch
Size: 1386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/3072a544/attachment.bin>
More information about the llvm-commits
mailing list