8000 `es/minifier`: truncate literal in bitwise and · Issue #10390 · swc-project/swc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

es/minifier: truncate literal in bitwise and #10390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Le0Developer opened this issue Apr 19, 2025 · 1 comment
Open

es/minifier: truncate literal in bitwise and #10390

Le0Developer opened this issue Apr 19, 2025 · 1 comment
Milestone

Comments

@Le0Developer
Copy link

Describe the feature

I recently I encountered a & 0xfffffffc in my codebase (blanks out the lower 2 bits to align to a 4 byte boundary in base64 decoding).

This could be a & -4 instead.

This applies to all bitwise operations but I haven't encountered others with such high values so far.

Although there's some cases where staying positive is actually shorter (eg a & 0x80000000 is shorter than a & -0x80000000 which would be the correct "in bounds" literal)

Babel plugin or link to the feature description

https://play.swc.rs/?version=1.11.21&code=H4sIAAAAAAAAA0vOzyvOz0nVy8lP10hUUFMwqEiDgGRNACgym%2BMbAAAA&config=H4sIAAAAAAAAA42VS47bMAxA9z1F4HUX7aJFMQeYXc8gKBblaCqLhkh5Ygxy99K%2FxJ3QRjdBzMeP%2BJM%2BvpxO1RvV1cvpQ%2F7KR2czQb5%2Fi4SGxPYqkoqHDqjOoeNqgrevsw3b3ACPGkA%2FqkUYEQlE5m0kWGRtSMEPW%2Bc1tl0Goo1MpOKvtJCY%2FrVfWMb3EXAuW%2FkZMYJNB8RYMiExNJA1xzXGaDsC09useBlPanMg1EKMsDA402XsVJ5c4IBJYj5TB9aZGh0oKGSoOfSgmUksMUsk6Sn5TNjBuTTN1NBP1tDbWCwrMeE6tUROq3i9YCA2viSthDPcqcEMl%2BJ%2BtgzeZOCS07PdG4a005M%2FAFKBaImSbUHzO2l4mac9a39oGZKXkeVB4TLfWpYJGimqCcErlR0rA5mD1s0MrtQwVrbWjrPgnfJRcGDAe5kVxTW9B64vWtBxo9ErQPprvTZVMzD3Ldzh40Ic4FfJkvUBWzRay5d9SkN7xngQoAW%2BoDtQkFYw7uMst8S12%2BclOZDRAKeqFJrA8yUgC8Bo4nRZPs2GrId4NE3E8%2BOaWBRuq2bV2tRM%2B765Lxm7CD3EvTH%2BjxU5pHK2fpzqdbOfthd%2BaUNpZfHC928rWlN5vB3TT9WiK5uMpqGcH5Of1UNpfTruUapAv1fLuZa3v8TDE%2F3PBgAA

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone May 13, 2025
@Le0Developer
Copy link
Author

Two more things i found:

  • the current optimization for a & 0xffffffff -> a | 0 does not apply for a & -1 which is identical.
  • bitshifts (a >> b) don't appear to qualify as "truncating to int". for example (a | 0) >>> 0 does not get reduced to a >>> 0 (same with (a | 0) >> 1)

Playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants
0