From d948b8fcb9d120afbbad5f26a74aa477caad99b0 Mon Sep 17 00:00:00 2001 From: Rick Lavoie Date: Wed, 15 Sep 2021 21:38:16 -0700 Subject: [PATCH] Mandatorily remove non-DefConst constants in HHIR Summary: In HHIR, a SSATmp can be a constant (hasConstVal() true), but it's source is not a DefConst. An example would be a function call which is known to return a constant. We try to const-prop all of these non-DefConst constants. That is, any instruction which takes one of these constants is changed instead to take the DefConst equivalent. This is important, as a SSATmp constant might not have any Vrefs defined (in the function call example, we don't write to %rax if the return value is known). This can lead to assertions being triggered. The simplifier can perform this const-prop. However, it was failing to retype dst SSATmp types, meaning it would miss some cases. Add a call to retypeDests to fix this. Also, in some situations we may not call the simplifier. In this case, we still need to do this "mandatory propagation", so do so. Reviewed By: oulgen Differential Revision: D30905689 fbshipit-source-id: c1f35639950fb0bb926ad9b3b5d49e2ac3df177f --- hphp/runtime/vm/jit/opt.cpp | 18 ++++++++++++++++++ hphp/runtime/vm/jit/simplify.cpp | 2 ++ 2 files changed, 20 insertions(+) diff --git a/hphp/runtime/vm/jit/opt.cpp b/hphp/runtime/vm/jit/opt.cpp index 2e0b5faaf2b..53952956aea 100644 --- a/hphp/runtime/vm/jit/opt.cpp +++ b/hphp/runtime/vm/jit/opt.cpp @@ -23,6 +23,7 @@ #include "hphp/runtime/vm/jit/ir-unit.h" #include "hphp/runtime/vm/jit/mutation.h" #include "hphp/runtime/vm/jit/print.h" +#include "hphp/runtime/vm/jit/simple-propagation.h" #include "hphp/runtime/vm/jit/simplify.h" #include "hphp/runtime/vm/jit/timer.h" #include "hphp/runtime/vm/jit/dce.h" @@ -161,6 +162,17 @@ uint64_t count_inline_returns(const IRUnit& unit) { return ret; } +void mandatoryPropagation(IRUnit& unit) { + forEachInst( + rpoSortCfg(unit), + [&] (IRInstruction* inst) { + copyProp(inst); + constProp(unit, inst); + retypeDests(inst, &unit); + } + ); +} + ////////////////////////////////////////////////////////////////////// } @@ -248,7 +260,13 @@ void optimize(IRUnit& unit, TransKind kind) { if (kind != TransKind::Profile && RuntimeOption::EvalHHIRSimplification) { rqtrace::EventGuard trace{"OPT_SIMPLIFY"}; doPass(unit, simplifyPass, DCE::Full); + } else { + // If we don't run the simplifier, we still need to run mandatory + // propagation at least to remove the use of non-DefConst + // constants. + mandatoryPropagation(unit); } + doPass(unit, fixBlockHints, DCE::None); if (kind == TransKind::Optimize) { diff --git a/hphp/runtime/vm/jit/simplify.cpp b/hphp/runtime/vm/jit/simplify.cpp index 60492d9f788..e4cf171dc53 100644 --- a/hphp/runtime/vm/jit/simplify.cpp +++ b/hphp/runtime/vm/jit/simplify.cpp @@ -40,6 +40,7 @@ #include "hphp/runtime/vm/jit/ir-builder.h" #include "hphp/runtime/vm/jit/irgen-internal.h" #include "hphp/runtime/vm/jit/minstr-effects.h" +#include "hphp/runtime/vm/jit/mutation.h" #include "hphp/runtime/vm/jit/simple-propagation.h" #include "hphp/runtime/vm/jit/translator-runtime.h" #include "hphp/runtime/vm/jit/type-array-elem.h" @@ -4010,6 +4011,7 @@ void simplifyInPlace(IRUnit& unit, IRInstruction* origInst) { copyProp(origInst); constProp(unit, origInst); + retypeDests(origInst, &unit); auto res = simplify(unit, origInst); // No simplification occurred; nothing to do. -- 2.11.4.GIT