Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 334233564d5f16fee1f4de3a35b5e358552138fb
https://github.com/WebKit/WebKit/commit/334233564d5f16fee1f4de3a35b5e358552138fb
Author: Yusuke Suzuki <[email protected]>
Date: 2026-04-30 (Thu, 30 Apr 2026)
Changed paths:
M Source/JavaScriptCore/b3/B3OptimizeAssociativeExpressionTrees.cpp
M Source/JavaScriptCore/b3/B3ReduceStrength.cpp
M Source/JavaScriptCore/b3/testb3.h
M Source/JavaScriptCore/b3/testb3_1.cpp
Log Message:
-----------
[JSC] Optimize bit-rotate idiom in B3
https://bugs.webkit.org/show_bug.cgi?id=313718
rdar://175920259
Reviewed by Yijia Huang and Keith Miller.
JavaScript does not have bit-rotate operation. If you would like to do
bit-rotate, then you need to write either,
(z << (32 - N)) | (z >>> N)
(z << (32 - N)) ^ (z >>> N)
While the above is performing multiple arithmetic operations, the intent
is "rotate-to-right N". This patch detects it in B3 and optimize it in
two places.
1. B3ReduceStrength simply detects the leaf pattern of the above and
transform it to rotate-to-right.
2. More complicated case is tree of them. For example,
(z << (32 - N)) ^ (z >>> M) ^ (z << (32 - M)) ^ (z >>> N) ...
Optimizing it in B3 reduce strength needs to traverse children in
upward and it makes reduce-strength loop much more costly. Thus we
do this in the appropriate phase: B3OptimizeAssociativeExpressionTrees.
B3OptimizeAssociativeExpressionTrees detects the tree of associative
expression (BitXor, BitOr, Add etc.) and attempt to optimize them by
combining constants. When we construct a tree for BitOr / BitXor, we
check leaves and attempt to fold a pattern
(z << (32 - N)) | (z >>> N)
(z << (32 - N)) ^ (z >>> N)
and replace leaf with rotate-to-right when we detect this.
Test: Source/JavaScriptCore/b3/testb3_1.cpp
* Source/JavaScriptCore/b3/B3OptimizeAssociativeExpressionTrees.cpp:
(JSC::B3::OptimizeAssociativeExpressionTrees::optimizeRootedTree):
* Source/JavaScriptCore/b3/B3ReduceStrength.cpp:
* Source/JavaScriptCore/b3/testb3.h:
* Source/JavaScriptCore/b3/testb3_1.cpp:
(testRotLWithImmShift):
(testRotRFromShiftOr):
(testRotRFromShiftXor):
(testRotRFromShiftXorReversed):
(testRotRFromShiftXorChainSHA256Sigma1_32):
(testRotRFromShiftXorChainSHA512Sigma1_64):
(testRotRFromShiftXorChainSHA256sigma0_32):
(testRotRFromShiftOrChainSHA256Sigma1_32):
(testRotRFromShiftXorChainSharedShiftOperand):
(testShiftOrDifferentBasesNoRotate):
(testShiftOrMismatchedAmountsNoRotate):
(run):
Canonical link: https://commits.webkit.org/312388@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications