From 4e3e4b6728bc3b1daafd4f8fe38b285ea0a06f70 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Tue, 6 Jul 2021 20:07:30 -0700 Subject: [PATCH 1/3] hdse should not regard OP_div as having side effect for C code --- src/mapleall/maple_me/src/hdse.cpp | 2 +- src/mapleall/maple_me/src/lfo_iv_canon.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index 6326d9581a..edf3a8e5b0 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -379,7 +379,7 @@ void HDSE::PropagateUseLive(MeExpr &meExpr) { bool HDSE::ExprHasSideEffect(const MeExpr &meExpr) const { Opcode op = meExpr.GetOp(); // in c language, OP_array has no side-effect - if (mirModule.IsCModule() && op == OP_array) { + if (mirModule.IsCModule() && (op == OP_array || op == OP_div)) { return false; } if (kOpcodeInfo.HasSideEffect(op)) { diff --git a/src/mapleall/maple_me/src/lfo_iv_canon.cpp b/src/mapleall/maple_me/src/lfo_iv_canon.cpp index c6e491ad15..f31a51890b 100644 --- a/src/mapleall/maple_me/src/lfo_iv_canon.cpp +++ b/src/mapleall/maple_me/src/lfo_iv_canon.cpp @@ -58,7 +58,7 @@ bool IVCanon::ResolveExprValue(MeExpr *x, ScalarMeExpr *phiLHS) { if (defStmt->GetOp() == OP_dassign) { // defstmt is %post = i, i is identified as IV // set %post is IV and use i's step value - scalar = static_cast(defStmt->GetRHS()); + scalar = dynamic_cast(defStmt->GetRHS()); if (scalar && scalar->GetOst() && IsScalarIV(scalar->GetOst())) { return true; } @@ -98,7 +98,7 @@ int32 IVCanon::ComputeIncrAmt(MeExpr *x, ScalarMeExpr *phiLHS, int32 *appearance CHECK_FATAL(scalar->GetDefBy() == kDefByStmt, "ComputeIncrAmt: cannot be here"); AssignMeStmt *defstmt = static_cast(scalar->GetDefStmt()); if (defstmt->GetOp() == OP_dassign) { - scalar = static_cast(defstmt->GetRHS()); + scalar = dynamic_cast(defstmt->GetRHS()); if (scalar && scalar->GetOst() && IsScalarIV(scalar->GetOst())) { int32_t stepVal = 0; if (IsScalarIV(scalar->GetOst(), &stepVal)) { -- Gitee From 82d478c1d41ae2536b5bf213ff72490699574b56 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Tue, 6 Jul 2021 20:07:30 -0700 Subject: [PATCH 2/3] hdse should not regard OP_div as having side effect for C code --- src/mapleall/maple_me/src/hdse.cpp | 2 +- src/mapleall/maple_me/src/lfo_iv_canon.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index 6326d9581a..edf3a8e5b0 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -379,7 +379,7 @@ void HDSE::PropagateUseLive(MeExpr &meExpr) { bool HDSE::ExprHasSideEffect(const MeExpr &meExpr) const { Opcode op = meExpr.GetOp(); // in c language, OP_array has no side-effect - if (mirModule.IsCModule() && op == OP_array) { + if (mirModule.IsCModule() && (op == OP_array || op == OP_div)) { return false; } if (kOpcodeInfo.HasSideEffect(op)) { diff --git a/src/mapleall/maple_me/src/lfo_iv_canon.cpp b/src/mapleall/maple_me/src/lfo_iv_canon.cpp index c6e491ad15..f31a51890b 100644 --- a/src/mapleall/maple_me/src/lfo_iv_canon.cpp +++ b/src/mapleall/maple_me/src/lfo_iv_canon.cpp @@ -58,7 +58,7 @@ bool IVCanon::ResolveExprValue(MeExpr *x, ScalarMeExpr *phiLHS) { if (defStmt->GetOp() == OP_dassign) { // defstmt is %post = i, i is identified as IV // set %post is IV and use i's step value - scalar = static_cast(defStmt->GetRHS()); + scalar = dynamic_cast(defStmt->GetRHS()); if (scalar && scalar->GetOst() && IsScalarIV(scalar->GetOst())) { return true; } @@ -98,7 +98,7 @@ int32 IVCanon::ComputeIncrAmt(MeExpr *x, ScalarMeExpr *phiLHS, int32 *appearance CHECK_FATAL(scalar->GetDefBy() == kDefByStmt, "ComputeIncrAmt: cannot be here"); AssignMeStmt *defstmt = static_cast(scalar->GetDefStmt()); if (defstmt->GetOp() == OP_dassign) { - scalar = static_cast(defstmt->GetRHS()); + scalar = dynamic_cast(defstmt->GetRHS()); if (scalar && scalar->GetOst() && IsScalarIV(scalar->GetOst())) { int32_t stepVal = 0; if (IsScalarIV(scalar->GetOst(), &stepVal)) { -- Gitee From 078480aa29dc874ad704ecb93bc07ab990270317 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Tue, 6 Jul 2021 21:02:46 -0700 Subject: [PATCH 3/3] same change to the dse phase --- src/mapleall/maple_me/src/dse.cpp | 4 ++++ src/mapleall/maple_me/src/hdse.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_me/src/dse.cpp b/src/mapleall/maple_me/src/dse.cpp index e6b31d3057..17ed67c1bf 100644 --- a/src/mapleall/maple_me/src/dse.cpp +++ b/src/mapleall/maple_me/src/dse.cpp @@ -37,6 +37,10 @@ using namespace utils; bool DSE::ExprHasSideEffect(const BaseNode &expr) const { Opcode op = expr.GetOpCode(); + // in c language, OP_array and OP_div has no side-effect + if (ssaTab.GetModule().IsCModule() && (op == OP_array || op == OP_div)) { + return false; + } if (kOpcodeInfo.HasSideEffect(op)) { return true; } diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index edf3a8e5b0..e09600b96e 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -378,7 +378,7 @@ void HDSE::PropagateUseLive(MeExpr &meExpr) { bool HDSE::ExprHasSideEffect(const MeExpr &meExpr) const { Opcode op = meExpr.GetOp(); - // in c language, OP_array has no side-effect + // in c language, OP_array and OP_div has no side-effect if (mirModule.IsCModule() && (op == OP_array || op == OP_div)) { return false; } -- Gitee