Fix optimization rules for narrow types: wrap i8 results to 8 bits. (#5409)
* 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. * Review feedback. * Review feedback, again.
This commit is contained in:
@@ -207,3 +207,36 @@
|
||||
(rule (simplify
|
||||
(select ty (uextend _ c @ (icmp _ _ _ _)) x y))
|
||||
(select ty c x y))
|
||||
|
||||
;; `x == x` is always true for integers; `x != x` is false. Strict
|
||||
;; inequalities are false, and loose inequalities are true.
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.Equal) x x))
|
||||
(iconst ty (imm64 1)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.NotEqual) x x))
|
||||
(iconst ty (imm64 0)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.UnsignedGreaterThan) x x))
|
||||
(iconst ty (imm64 0)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.UnsignedGreaterThanOrEqual) x x))
|
||||
(iconst ty (imm64 1)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.SignedGreaterThan) x x))
|
||||
(iconst ty (imm64 0)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.SignedGreaterThanOrEqual) x x))
|
||||
(iconst ty (imm64 1)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.UnsignedLessThan) x x))
|
||||
(iconst ty (imm64 0)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.UnsignedLessThanOrEqual) x x))
|
||||
(iconst ty (imm64 1)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.SignedLessThan) x x))
|
||||
(iconst ty (imm64 0)))
|
||||
(rule (simplify
|
||||
(icmp ty (IntCC.SignedLessThanOrEqual) x x))
|
||||
(iconst ty (imm64 1)))
|
||||
|
||||
Reference in New Issue
Block a user