Commit 68f8693
committed
[optimize-instructions] Fold relational comparisons of tee/get pairs
Fixes #7672.
`LocalCSE` rewrites repeated subexpressions as a `local.tee` followed
by a `local.get`, so two identical operands to a relational comparison
can reach `OptimizeInstructions` as
`(rel (local.tee $n X) (local.get $n))`. The pass has a helper for
exactly this shape (`areMatchingTeeAndGet`) but consults it only in
the `RefEq` and `Select` handlers, not in `optimizeRelational`. The
comparison survives into the `-O3` output and blocks subsequent
dead-code elimination.
Add the fold at the top of `optimizeRelational`. The result of a
self-comparison is a constant (`gt`/`lt`/`ne` -> 0, `ge`/`le`/`eq`
-> 1). X is evaluated once for its side effects and then dropped, so
the reproduction's load chain preserves its original trap behavior.
Refs #6719 -- the drop-before-unreachable fix that made the residual
`drop; unreachable` visible in the issue's output.1 parent 6c97a76 commit 68f8693
2 files changed
Lines changed: 62 additions & 0 deletions
File tree
- src/passes
- test/lit/passes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4990 | 4990 | | |
4991 | 4991 | | |
4992 | 4992 | | |
| 4993 | + | |
| 4994 | + | |
| 4995 | + | |
| 4996 | + | |
| 4997 | + | |
| 4998 | + | |
| 4999 | + | |
| 5000 | + | |
| 5001 | + | |
| 5002 | + | |
| 5003 | + | |
| 5004 | + | |
| 5005 | + | |
| 5006 | + | |
| 5007 | + | |
| 5008 | + | |
| 5009 | + | |
| 5010 | + | |
| 5011 | + | |
| 5012 | + | |
| 5013 | + | |
| 5014 | + | |
| 5015 | + | |
| 5016 | + | |
| 5017 | + | |
| 5018 | + | |
| 5019 | + | |
| 5020 | + | |
| 5021 | + | |
| 5022 | + | |
| 5023 | + | |
| 5024 | + | |
| 5025 | + | |
| 5026 | + | |
| 5027 | + | |
| 5028 | + | |
| 5029 | + | |
| 5030 | + | |
| 5031 | + | |
| 5032 | + | |
| 5033 | + | |
4993 | 5034 | | |
4994 | 5035 | | |
4995 | 5036 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments