MaxGraey edited issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp slt_imm x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
.
forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
bjorn3 commented on issue #4607:
This wouldn't help on platforms without flag registers, right? Those have icmp and bint merged together already. If anything it would prevent icmp+brz/brnz fusion I think, even on platforms with flag registers.
MaxGraey commented on issue #4607:
Hmm, so perhaps it's better to do on lower level (may be ISTLE) for only specific platforms?
MaxGraey edited a comment on issue #4607:
Hmm, so perhaps it's better to do on lower level (may be ISLE) for only specific platforms?
MaxGraey edited a comment on issue #4607:
Hmm, so perhaps it's better to do on lower level (may be ISLE) for only specific platforms after icmp+brz/brnz fusion?
bjorn3 commented on issue #4607:
I think so.
cfallin commented on issue #4607:
We can definitely incorporate this as a lowering rule case in the backends. The ISLE and lowering machinery is smart enough to do the right thing for the
(brnz (icmp ...))
case and allow for a rule for(icmp (IntCC.NP) ...)
when used directly to compute that value. cc @elliottt as he is in the middle of br+compare stuff in x86-64 right now...
MaxGraey edited issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp_imm slt x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
.
forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
MaxGraey edited issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp_imm slt x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
. Forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
MaxGraey edited issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp_imm slt x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
. Forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
Update Implementation Plan
Write necessary rules on ISLE insteadsimple_opt.rs
MaxGraey edited issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp_imm slt x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
. Forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
Updated Implementation Plan
Write necessary rules on ISLE instead
simple_opt.rs
MaxGraey edited issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp_imm slt x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
. Forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
Updated Implementation Plan
Write necessary rules on ISLE instead in
simple_opt.rs
MaxGraey edited issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp_imm slt x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
. Forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
Updated Implementation Plan
Write necessary rules on ISLE instead in
simple_opt.rs
elliottt closed issue #4607:
Feature
Simple optimization which rewrite
x < 0
(icmp_imm slt x, 0
) tox >>> bit_size(ty) - 1
(ushr_imm x, 31 | 63
).Benefit
x < 0
is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0
to31
or63
has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32
/bint.i64
aftericmp
. Forushr
/ushr_imm
it is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clif
andfiletests/simple_preopt/simplily64.clif
Updated Implementation Plan
Write necessary rules on ISLE instead in
simple_opt.rs
Last updated: Dec 23 2024 at 12:05 UTC