[PATCH] D156442: [llvm][RISCV][Backend]
Panagiotis K via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 27 08:49:43 PDT 2023
karouzakisp created this revision.
karouzakisp added a reviewer: craig.topper.
karouzakisp added a project: LLVM.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
karouzakisp requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Added zext flag named was_sext in IR
RISCVCodeGenPrepare does a conversion that converts all the
zext instructions with the flag back to sext.
Repository:
rG LLVM Github Monorepo
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.544788.patch
Type: text/x-patch
Size: 1386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/97e90248/attachment.bin>
More information about the llvm-commits
mailing list