-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix optimization rules for narrow types: wrap i8 results to 8 bits.
This fixes #5405. In the egraph mid-end's optimization rules, we were rewriting e.g. imuls of two iconsts to an iconst of the result, but without masking off the high bits (beyond the result type's width). This was producing iconsts with set high bits beyond their types' width, which is not legal. In addition, this PR adds some optimizations to the algebraic rules to recognize e.g. `x == x` (and all other integer comparison operators) and resolve to 1 or 0 as appropriate.
- Loading branch information
Showing
6 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
test optimize | ||
set opt_level=none | ||
set use_egraphs=true | ||
target x86_64 | ||
|
||
function %f0() -> i8 { | ||
block0: | ||
v1 = iconst.i8 51 | ||
v2 = imul.i8 v1, v1 | ||
return v2 | ||
} | ||
|
||
; check: v9 = iconst.i8 41 | ||
; nextln: return v9 | ||
|
||
function %f1() -> i16 { | ||
block0: | ||
v1 = iconst.i16 1 | ||
v2 = bnot.i16 v1 | ||
return v2 | ||
} | ||
|
||
; check: v3 = iconst.i16 0xfffe | ||
; nextln: return v3 | ||
|
||
function %f2(i8) -> i8 { | ||
block0(v1: i8): | ||
v2 = icmp eq v1, v1 | ||
return v2 | ||
} | ||
|
||
; check: v3 = iconst.i8 1 | ||
; check: return v3 | ||
|
||
function %f3(i8) -> i8 { | ||
block0(v1: i8): | ||
v2 = icmp ne v1, v1 | ||
return v2 | ||
} | ||
|
||
; check: v3 = iconst.i8 0 | ||
; check: return v3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test interpret | ||
test run | ||
set opt_level=speed_and_size | ||
set use_egraphs=true | ||
target aarch64 | ||
|
||
function %a(i64) -> i8 system_v { | ||
block0(v0: i64): | ||
v6 = iconst.i8 51 | ||
v17 = imul v6, v6 ; v6 = 51, v6 = 51 | ||
v18 = icmp eq v17, v17 | ||
v52 = imul v18, v18 | ||
return v52 | ||
} | ||
|
||
; run: %a(129) == 1 |