From 64192450d0a54c23338d104f4cf96718a4d29e3d Mon Sep 17 00:00:00 2001 From: linma Date: Wed, 8 Sep 2021 20:49:40 -0700 Subject: [PATCH 1/3] fix bugs: OP_div has no side effect in c language in hdse phase ivcanon: use signed type in tripcount expression if there's sub op seqvec: use ivarexpr tyidx in ConsecutiveMem computation, primtype may not be consistent with point to type --- src/mapleall/maple_me/src/hdse.cpp | 2 +- src/mapleall/maple_me/src/lfo_iv_canon.cpp | 3 ++- src/mapleall/maple_me/src/seqvec.cpp | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index 9e3004d924..dd67943831 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -389,7 +389,7 @@ void HDSE::PropagateUseLive(MeExpr &meExpr) { bool HDSE::ExprHasSideEffect(const MeExpr &meExpr) const { Opcode op = meExpr.GetOp(); // in c language, OP_array and OP_div has no side-effect - if (mirModule.IsCModule() && (op == OP_array || op == OP_div)) { + if (mirModule.IsCModule() && (op == OP_array || op == OP_div || op == OP_rem)) { 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 f290426c88..c7e5891fe5 100644 --- a/src/mapleall/maple_me/src/lfo_iv_canon.cpp +++ b/src/mapleall/maple_me/src/lfo_iv_canon.cpp @@ -294,7 +294,8 @@ void IVCanon::ComputeTripCount() { } // form the trip count expression - PrimType primTypeUsed = testExpr->GetOpnd(0)->GetPrimType(); + PrimType primTypeUsed = (!ivdesc->initExpr->IsZero()) ? + GetSignedPrimType(testExpr->GetOpnd(0)->GetPrimType()) : testExpr->GetOpnd(0)->GetPrimType(); PrimType divPrimType = primTypeUsed; if (ivdesc->stepValue < 0) { divPrimType = GetSignedPrimType(divPrimType); diff --git a/src/mapleall/maple_me/src/seqvec.cpp b/src/mapleall/maple_me/src/seqvec.cpp index 722a86c68e..18cad387df 100644 --- a/src/mapleall/maple_me/src/seqvec.cpp +++ b/src/mapleall/maple_me/src/seqvec.cpp @@ -351,7 +351,12 @@ bool SeqVectorize::CanSeqVecRhs(MeExpr *rhs1, MeExpr *rhs2) { if (rhs1->GetMeOp() == maple::kMeOpIvar) { IvarMeExpr *rhs1Ivar = static_cast(rhs1); IvarMeExpr *rhs2Ivar = static_cast(rhs2); - if (IsIvarExprConsecutiveMem(rhs1Ivar, rhs2Ivar, rhs1Ivar->GetPrimType())) { + MIRType &mirType = GetTypeFromTyIdx(rhs1Ivar->GetTyIdx()); + CHECK_FATAL(mirType.GetKind() == kTypePointer, "iassign must have pointer type"); + MIRPtrType *ptrType = static_cast(&mirType); + PrimType diffType = (ptrType->GetPointedType()->GetPrimType() != PTY_agg) ? + ptrType->GetPointedType()->GetPrimType() : rhs1Ivar->GetPrimType(); + if (IsIvarExprConsecutiveMem(rhs1Ivar, rhs2Ivar, diffType)) { return true; } } -- Gitee From f4e39c483a3df41f1b4b26309a927d97605ced0d Mon Sep 17 00:00:00 2001 From: linma Date: Thu, 9 Sep 2021 14:56:41 -0700 Subject: [PATCH 2/3] Revert "fix bugs: OP_div has no side effect in c language in hdse phase" This reverts commit 64192450d0a54c23338d104f4cf96718a4d29e3d. --- src/mapleall/maple_me/src/hdse.cpp | 2 +- src/mapleall/maple_me/src/lfo_iv_canon.cpp | 3 +-- src/mapleall/maple_me/src/seqvec.cpp | 7 +------ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index dd67943831..9e3004d924 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -389,7 +389,7 @@ void HDSE::PropagateUseLive(MeExpr &meExpr) { bool HDSE::ExprHasSideEffect(const MeExpr &meExpr) const { Opcode op = meExpr.GetOp(); // in c language, OP_array and OP_div has no side-effect - if (mirModule.IsCModule() && (op == OP_array || op == OP_div || op == OP_rem)) { + 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 c7e5891fe5..f290426c88 100644 --- a/src/mapleall/maple_me/src/lfo_iv_canon.cpp +++ b/src/mapleall/maple_me/src/lfo_iv_canon.cpp @@ -294,8 +294,7 @@ void IVCanon::ComputeTripCount() { } // form the trip count expression - PrimType primTypeUsed = (!ivdesc->initExpr->IsZero()) ? - GetSignedPrimType(testExpr->GetOpnd(0)->GetPrimType()) : testExpr->GetOpnd(0)->GetPrimType(); + PrimType primTypeUsed = testExpr->GetOpnd(0)->GetPrimType(); PrimType divPrimType = primTypeUsed; if (ivdesc->stepValue < 0) { divPrimType = GetSignedPrimType(divPrimType); diff --git a/src/mapleall/maple_me/src/seqvec.cpp b/src/mapleall/maple_me/src/seqvec.cpp index 18cad387df..722a86c68e 100644 --- a/src/mapleall/maple_me/src/seqvec.cpp +++ b/src/mapleall/maple_me/src/seqvec.cpp @@ -351,12 +351,7 @@ bool SeqVectorize::CanSeqVecRhs(MeExpr *rhs1, MeExpr *rhs2) { if (rhs1->GetMeOp() == maple::kMeOpIvar) { IvarMeExpr *rhs1Ivar = static_cast(rhs1); IvarMeExpr *rhs2Ivar = static_cast(rhs2); - MIRType &mirType = GetTypeFromTyIdx(rhs1Ivar->GetTyIdx()); - CHECK_FATAL(mirType.GetKind() == kTypePointer, "iassign must have pointer type"); - MIRPtrType *ptrType = static_cast(&mirType); - PrimType diffType = (ptrType->GetPointedType()->GetPrimType() != PTY_agg) ? - ptrType->GetPointedType()->GetPrimType() : rhs1Ivar->GetPrimType(); - if (IsIvarExprConsecutiveMem(rhs1Ivar, rhs2Ivar, diffType)) { + if (IsIvarExprConsecutiveMem(rhs1Ivar, rhs2Ivar, rhs1Ivar->GetPrimType())) { return true; } } -- Gitee From d630dd7c4964b5457aed3cb26ce34e4513ef3a37 Mon Sep 17 00:00:00 2001 From: linma Date: Thu, 9 Sep 2021 15:12:02 -0700 Subject: [PATCH 3/3] fix bugs: OP_div has no side effect in c language in hdse phase ivcanon: use signed type in tripcount expression if there's sub op seqvec: skip vectorization if ivarmeexpr point-to type is not primitive interger --- src/mapleall/maple_me/src/hdse.cpp | 2 +- src/mapleall/maple_me/src/lfo_iv_canon.cpp | 3 ++- src/mapleall/maple_me/src/seqvec.cpp | 11 ++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index 9e3004d924..dd67943831 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -389,7 +389,7 @@ void HDSE::PropagateUseLive(MeExpr &meExpr) { bool HDSE::ExprHasSideEffect(const MeExpr &meExpr) const { Opcode op = meExpr.GetOp(); // in c language, OP_array and OP_div has no side-effect - if (mirModule.IsCModule() && (op == OP_array || op == OP_div)) { + if (mirModule.IsCModule() && (op == OP_array || op == OP_div || op == OP_rem)) { 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 f290426c88..c7e5891fe5 100644 --- a/src/mapleall/maple_me/src/lfo_iv_canon.cpp +++ b/src/mapleall/maple_me/src/lfo_iv_canon.cpp @@ -294,7 +294,8 @@ void IVCanon::ComputeTripCount() { } // form the trip count expression - PrimType primTypeUsed = testExpr->GetOpnd(0)->GetPrimType(); + PrimType primTypeUsed = (!ivdesc->initExpr->IsZero()) ? + GetSignedPrimType(testExpr->GetOpnd(0)->GetPrimType()) : testExpr->GetOpnd(0)->GetPrimType(); PrimType divPrimType = primTypeUsed; if (ivdesc->stepValue < 0) { divPrimType = GetSignedPrimType(divPrimType); diff --git a/src/mapleall/maple_me/src/seqvec.cpp b/src/mapleall/maple_me/src/seqvec.cpp index 722a86c68e..5d75ed30eb 100644 --- a/src/mapleall/maple_me/src/seqvec.cpp +++ b/src/mapleall/maple_me/src/seqvec.cpp @@ -351,7 +351,16 @@ bool SeqVectorize::CanSeqVecRhs(MeExpr *rhs1, MeExpr *rhs2) { if (rhs1->GetMeOp() == maple::kMeOpIvar) { IvarMeExpr *rhs1Ivar = static_cast(rhs1); IvarMeExpr *rhs2Ivar = static_cast(rhs2); - if (IsIvarExprConsecutiveMem(rhs1Ivar, rhs2Ivar, rhs1Ivar->GetPrimType())) { + MIRType &mirType = GetTypeFromTyIdx(rhs1Ivar->GetTyIdx()); + CHECK_FATAL(mirType.GetKind() == kTypePointer, "iassign must have pointer type"); + MIRPtrType *ptrType = static_cast(&mirType); + // skip vectorize if pointto type is agg, offset between + // arr[i] and arr[i+1] may be larger than vector width + if (!IsPrimitiveInteger(ptrType->GetPointedType()->GetPrimType())) { + return false; + } + PrimType diffType = ptrType->GetPointedType()->GetPrimType(); + if (IsIvarExprConsecutiveMem(rhs1Ivar, rhs2Ivar, diffType)) { return true; } } -- Gitee