diff --git a/IDEHelper/Backend/BeMCContext.cpp b/IDEHelper/Backend/BeMCContext.cpp index 40485635..49f2caff 100644 --- a/IDEHelper/Backend/BeMCContext.cpp +++ b/IDEHelper/Backend/BeMCContext.cpp @@ -16147,7 +16147,7 @@ void BeMCContext::Generate(BeFunction* function) mcMemberRef.mKind = BeMCOperandKind_VRegLoad; AllocInst(BeMCInstKind_Mov, mcMemberRef, mcValue); - // Our InsertValue always modifies the source aggregrate, it does not make a copy like LLVM's InsertValue would infer. + // Our InsertValue always modifies the source aggregate, it does not make a copy like LLVM's InsertValue would infer. // This is okay because of Beef front end knowledge, but is not general purpose. result = mcAgg; } @@ -16157,6 +16157,7 @@ void BeMCContext::Generate(BeFunction* function) auto castedInst = (BeNumericCastInst*)inst; auto mcValue = GetOperand(castedInst->mValue); auto fromType = GetType(mcValue); + if (fromType == castedInst->mToType) { // If it's just a sign change then leave it alone @@ -16179,6 +16180,10 @@ void BeMCContext::Generate(BeFunction* function) bool doSignExtension = (toType->IsIntable()) && (fromType->IsIntable()) && (toType->mSize > fromType->mSize) && (castedInst->mToSigned) && (castedInst->mValSigned); if ((toType->IsFloat()) && (fromType->IsIntable()) && (castedInst->mValSigned)) doSignExtension = true; + + if (mcValue.IsImmediate()) + doSignExtension = false; + if (doSignExtension) { AllocInst(BeMCInstKind_MovSX, toValue, mcValue); diff --git a/IDEHelper/Tests/src/Ints.bf b/IDEHelper/Tests/src/Ints.bf index f9d35fcd..07836e3a 100644 --- a/IDEHelper/Tests/src/Ints.bf +++ b/IDEHelper/Tests/src/Ints.bf @@ -38,6 +38,10 @@ namespace Tests { Test.Assert(0b0111010110111100110100010101 == 123456789); Test.Assert(0o726746425 == 123456789); + + int i0 = 5; + int i1 = i0 % 1; + Test.Assert(i1 == 0); } } }