From fc250857642ca38ac8b83ae7486513fadf3ab742 Mon Sep 17 00:00:00 2001 From: KasonChan Date: Wed, 7 Jul 2021 14:56:59 +0800 Subject: [PATCH] fix lftr bug --- src/mapleall/maple_ir/include/mir_type.h | 1 + src/mapleall/maple_ir/src/mir_type.cpp | 16 ++++++++++++++++ src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp | 11 ++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_ir/include/mir_type.h b/src/mapleall/maple_ir/include/mir_type.h index b8081e200f..aff6f1b2fc 100644 --- a/src/mapleall/maple_ir/include/mir_type.h +++ b/src/mapleall/maple_ir/include/mir_type.h @@ -40,6 +40,7 @@ extern bool VerifyPrimType(PrimType primType1, PrimType primType2); // ver extern uint32 GetPrimTypeSize(PrimType primType); // answer in bytes; 0 if unknown extern uint32 GetPrimTypeP2Size(PrimType primType); // answer in bytes in power-of-two. extern PrimType GetSignedPrimType(PrimType pty); // return signed version +extern PrimType GetUnsignedPrimType(PrimType pty); // return unsigned version extern uint32 GetPrimTypeLanes(PrimType pty); // lane size if vector extern const char *GetPrimTypeName(PrimType primType); extern const char *GetPrimTypeJavaName(PrimType primType); diff --git a/src/mapleall/maple_ir/src/mir_type.cpp b/src/mapleall/maple_ir/src/mir_type.cpp index 1ee627a1ed..dfdec26791 100644 --- a/src/mapleall/maple_ir/src/mir_type.cpp +++ b/src/mapleall/maple_ir/src/mir_type.cpp @@ -344,6 +344,22 @@ PrimType GetSignedPrimType(PrimType pty) { return pty; } +// return the unsigned version that has the same size +PrimType GetUnsignedPrimType(PrimType pty) { + switch (pty) { + case PTY_i64: + return PTY_u64; + case PTY_i8: + return PTY_u8; + case PTY_i16: + return PTY_u16; + case PTY_i32: + return PTY_u32; + default: ; + } + return pty; +} + const char *GetPrimTypeName(PrimType primType) { #define LOAD_ALGO_PRIMARY_TYPE switch (primType) { diff --git a/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp b/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp index 7575b2e7cd..d221dd3f15 100644 --- a/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp +++ b/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp @@ -80,7 +80,7 @@ ScalarMeExpr *SSAEPre::FindScalarVersion(ScalarMeExpr *scalar, MeStmt *stmt) { // RETURN: regorvar < 100 + p (need to find p's SSA version there) // 100 + p is added to EPRE work list OpMeExpr *SSAEPre::FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) { - MeExpr *compare = compOcc->GetMeExpr(); + auto *compare = static_cast(compOcc->GetMeExpr()); // determine the ith operand of workCand that is the jth operand of compare OpMeExpr *x = static_cast(workCand->GetTheMeExpr()); size_t i; @@ -139,6 +139,15 @@ OpMeExpr *SSAEPre::FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) { hashedSide = irMap->HashMeExpr(newSide); BuildWorkListExpr(*compOcc->GetMeStmt(), compOcc->GetSequence(), *hashedSide, false, nullptr, true, true); } + // when compare with 0, signed/unsigned integers have different behaviour + if (hashedSide->IsZero() && + IsSignedInteger(regorvar->GetPrimType()) != IsSignedInteger(compare->GetOpndType()) && + compare->GetOp() != OP_ne && compare->GetOp() != OP_eq) { + auto cmpType = IsSignedInteger(regorvar->GetPrimType()) ? GetUnsignedPrimType(regorvar->GetPrimType()) : + GetSignedPrimType(regorvar->GetPrimType()) + regorvar = irMap->CreateMeExprTypeCvt(cmpType, regorvar->GetPrimType(), *regorvar); + hashedSide->SetPtyp(cmpType); + } OpMeExpr newcompare(-1, compare->GetOp(), compare->GetPrimType(), 2); newcompare.SetOpndType(regorvar->GetPrimType()); newcompare.SetOpnd(j, regorvar); -- Gitee