From eb0cd3aefbece52726b7816f4cd2c14c39f3cbd6 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 30 Dec 2021 06:56:00 -0500 Subject: [PATCH] Did proper badOps handling for both arg0 and arg1 being immediates --- IDEHelper/Backend/BeMCContext.cpp | 14 ++++++++++---- IDEHelper/Tests/src/Operators.bf | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/IDEHelper/Backend/BeMCContext.cpp b/IDEHelper/Backend/BeMCContext.cpp index 77dbb095..7ae5a633 100644 --- a/IDEHelper/Backend/BeMCContext.cpp +++ b/IDEHelper/Backend/BeMCContext.cpp @@ -9060,7 +9060,15 @@ bool BeMCContext::DoLegalization() if (isMov_R64_IMM64) doStdCheck = false; bool is3FormMul = false; - if ((isIntMul) && (inst->mResult)) + bool badOps = false; + + // Two immediates are never allowed. This can happen in cases like '(a % 1) * 2' + if ((arg0.IsImmediate()) && (arg1.IsImmediate())) + { + badOps = true; + doStdCheck = true; + } + else if ((isIntMul) && (inst->mResult)) { is3FormMul = true; if (inst->mArg1.IsImmediateInt()) @@ -9083,15 +9091,13 @@ bool BeMCContext::DoLegalization() } } - // Int 3-form mul does not follow these rules if (doStdCheck) { bool isIncOrDec = false; isIncOrDec = (((inst->mKind == BeMCInstKind_Add) || (inst->mKind == BeMCInstKind_Sub)) && (arg1.IsImmediateInt()) && (arg1.mImmediate == 1)); - - bool badOps = false; + if ((!isIncOrDec) && (!isIntMul) && (!isIntDiv)) { if ((arg0.MayBeMemory()) && (arg1.MayBeMemory())) diff --git a/IDEHelper/Tests/src/Operators.bf b/IDEHelper/Tests/src/Operators.bf index cdd1d04a..3e2f3f6a 100644 --- a/IDEHelper/Tests/src/Operators.bf +++ b/IDEHelper/Tests/src/Operators.bf @@ -377,6 +377,8 @@ namespace Tests } } + public struct Vector2 : this(float x, float y); + [Test] public static void TestBasics() { @@ -492,6 +494,11 @@ namespace Tests let oai2 = OuterOp2.InnerOp.Op(2.0f, 200); Test.Assert(oai2 == 202.0f);*/ + + const int c0 = 1; + const int32 c1 = 1; + int i0 = 0; + var tVal = Vector2((i0 % c0) * (c1 + c1), 1); } struct IntStruct