Skip to content

Commit dd0db25

Browse files
DadaIsCrazymibrunin
authored andcommitted
[Backport] Security bug 1509576
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/5114883: Merged: [turboshaft] Fix StructuralOptimization because of ignored side-effects Side-effects in the 1st else block were not taken into account. Drive-by: minor cleanups to StructuralOptimizationReducer. Bug: v8:12783, chromium:1509576 (cherry picked from commit 4a664b390577de3d3572010da0dc1138d78ab2c4) Change-Id: Id4e230ee0fd408c821747d3350d688c8b0098ae3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5114883 Reviewed-by: Matthias Liedtke <[email protected]> Commit-Queue: Matthias Liedtke <[email protected]> Auto-Submit: Darius Mercadier <[email protected]> Cr-Commit-Position: refs/branch-heads/12.0@{#20} Cr-Branched-From: ed7b4caf1fb8184ad9e24346c84424055d4d430a-refs/heads/12.0.267@{#1} Cr-Branched-From: 210e75b19db4352c9b78dce0bae11c2dc3077df4-refs/heads/main@{#90651} Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/530060 Reviewed-by: Allan Sandfeld Jensen <[email protected]>
1 parent 17bc3bc commit dd0db25

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

chromium/v8/src/compiler/turboshaft/structural-optimization-reducer.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace v8::internal::compiler::turboshaft {
8080
template <class Next>
8181
class StructuralOptimizationReducer : public Next {
8282
public:
83-
using Next::Asm;
83+
TURBOSHAFT_REDUCER_BOILERPLATE()
8484

8585
OpIndex ReduceInputGraphBranch(OpIndex input_index, const BranchOp& branch) {
8686
LABEL_BLOCK(no_change) {
@@ -100,6 +100,13 @@ class StructuralOptimizationReducer : public Next {
100100

101101
OpIndex switch_var = OpIndex::Invalid();
102102
while (true) {
103+
// The "false" destination will be inlined before the switch is emitted,
104+
// so it should only contain pure operations.
105+
if (!ContainsOnlyPureOps(current_branch->if_false, Asm().input_graph())) {
106+
TRACE("\t [break] End of only-pure-ops cascade reached.\n");
107+
break;
108+
}
109+
103110
// If we encounter a condition that is not equality, we can't turn it
104111
// into a switch case.
105112
const EqualOp* equal = Asm()
@@ -116,17 +123,11 @@ class StructuralOptimizationReducer : public Next {
116123
// MachineOptimizationReducer should normalize equality to put constants
117124
// right.
118125
const Operation& right_op = Asm().input_graph().Get(equal->right());
119-
if (!right_op.Is<ConstantOp>()) {
120-
TRACE("\t [bailout] No constant on the right side of Equal.\n");
126+
if (!right_op.Is<Opmask::kWord32Constant>()) {
127+
TRACE("\t [bailout] No Word32 constant on the right side of Equal.\n");
121128
break;
122129
}
123-
124-
// We can only turn Word32 constant equals to switch cases.
125130
const ConstantOp& const_op = right_op.Cast<ConstantOp>();
126-
if (const_op.kind != ConstantOp::Kind::kWord32) {
127-
TRACE("\t [bailout] Constant is not of type Word32.\n");
128-
break;
129-
}
130131

131132
// If we encounter equal to a different value, we can't introduce
132133
// a switch.
@@ -164,13 +165,6 @@ class StructuralOptimizationReducer : public Next {
164165

165166
// Iterate to the next if_false block in the cascade.
166167
current_branch = &maybe_branch.template Cast<BranchOp>();
167-
168-
// As long as the else blocks contain only pure ops, we can keep
169-
// traversing the if-else cascade.
170-
if (!ContainsOnlyPureOps(current_branch->if_false, Asm().input_graph())) {
171-
TRACE("\t [break] End of only-pure-ops cascade reached.\n");
172-
break;
173-
}
174168
}
175169

176170
// Probably better to keep short if-else cascades as they are.
@@ -186,7 +180,7 @@ class StructuralOptimizationReducer : public Next {
186180
InlineAllOperationsWithoutLast(block);
187181
}
188182

189-
TRACE("[reduce] Successfully emit a Switch with %z cases.", cases.size());
183+
TRACE("[reduce] Successfully emit a Switch with %zu cases.", cases.size());
190184

191185
// The last current_if_true block that ends the cascade becomes the default
192186
// case.

0 commit comments

Comments
 (0)