From 514088d64a7b4d32ca7bc45943712bd344bc6bf5 Mon Sep 17 00:00:00 2001 From: William Chen Date: Tue, 4 Jan 2022 11:13:35 -0800 Subject: [PATCH] Do not expand memcpy/memset if it has a return value --- src/mapleall/maple_be/include/be/lower.h | 2 +- src/mapleall/maple_be/src/be/lower.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mapleall/maple_be/include/be/lower.h b/src/mapleall/maple_be/include/be/lower.h index c61894d284..63f6c11ac3 100644 --- a/src/mapleall/maple_be/include/be/lower.h +++ b/src/mapleall/maple_be/include/be/lower.h @@ -146,7 +146,7 @@ class CGLowerer { BaseNode *LowerCArray(ArrayNode &array); DassignNode *SaveReturnValueInLocal(StIdx, uint16); - void LowerCallStmt(StmtNode&, StmtNode*&, BlockNode&, MIRType *retty = nullptr, bool uselvar = false); + void LowerCallStmt(StmtNode&, StmtNode*&, BlockNode&, MIRType *retty = nullptr, bool uselvar = false, bool isIntrinAssign = false); BlockNode *LowerCallAssignedStmt(StmtNode &stmt, bool uselvar = false); bool LowerStructReturn(BlockNode &blk, StmtNode *stmt, StmtNode *nextStmt, bool &lvar); BlockNode *LowerMemop(StmtNode&); diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index 2442510c69..7e90028bc9 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -1135,7 +1135,7 @@ BaseNode *CGLowerer::LowerRem(BaseNode &expr, BlockNode &blk) { } /* to lower call (including icall) and intrinsicall statements */ -void CGLowerer::LowerCallStmt(StmtNode &stmt, StmtNode *&nextStmt, BlockNode &newBlk, MIRType *retty, bool uselvar) { +void CGLowerer::LowerCallStmt(StmtNode &stmt, StmtNode *&nextStmt, BlockNode &newBlk, MIRType *retty, bool uselvar, bool isIntrinAssign) { StmtNode *newStmt = nullptr; if (stmt.GetOpCode() == OP_intrinsiccall) { auto &intrnNode = static_cast(stmt); @@ -1156,8 +1156,9 @@ void CGLowerer::LowerCallStmt(StmtNode &stmt, StmtNode *&nextStmt, BlockNode &ne newStmt->SetSrcPos(stmt.GetSrcPos()); newBlk.AddStatement(newStmt); if (CGOptions::GetInstance().GetOptimizeLevel() >= CGOptions::kLevel2 && stmt.GetOpCode() == OP_intrinsiccall) { - // Try to expand memset and memcpy call lowered from intrinsiccall - BlockNode *blkLowered = LowerMemop(*newStmt); + /* Try to expand memset and memcpy call lowered from intrinsiccall */ + /* Skip expansion if call returns a value that is used later. */ + BlockNode *blkLowered = isIntrinAssign ? nullptr : LowerMemop(*newStmt); if (blkLowered != nullptr) { newBlk.RemoveStmt(newStmt); newBlk.AppendStatementsFromBlock(*blkLowered); @@ -1302,7 +1303,7 @@ BlockNode *CGLowerer::GenBlockNode(StmtNode &newCall, const CallReturnVector &p2 blk->AddStatement(cmnt); } CHECK_FATAL(dStmt == nullptr || dStmt->GetNext() == nullptr, "make sure dStmt or dStmt's next is nullptr"); - LowerCallStmt(newCall, dStmt, *blk, retType, uselvar ? true : false); + LowerCallStmt(newCall, dStmt, *blk, retType, uselvar ? true : false, opcode == OP_intrinsiccallassigned); if (!uselvar && dStmt != nullptr) { dStmt->SetSrcPos(newCall.GetSrcPos()); blk->AddStatement(dStmt); -- Gitee