Repository navigation
Conversation
Subscribe to Label Actioncc @avanhatt, @cfallin, @fitzgen, @mmcloughlin DetailsThis issue or pull request has been labeled: "cranelift", "isle"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
cfallin
left a comment
There was a problem hiding this comment.
Thanks! The new rules look good generally. Just one question below about a possible pessimization.
| ; check: return v4 | ||
| ; check: v5 = iconst.i32 0 | ||
| ; check: v6 = isub v5, v0 | ||
| ; check: return v6 |
There was a problem hiding this comment.
This seems like a regression -- we won't use the native negation instruction anymore but instead will load a zero-constant and do a subtract. Could you look into what's going on here (cost function discrepancies or something else)?
There was a problem hiding this comment.
I believe it's because of the rule ~x + C → (C - 1) - x.
When C=1, both rules match:
~x + 1 → (1 - 1) - x → 0 - x(added rule in this pr)~x + 1 → -x(existing one)
The cost model assigns both candidates as 4: ineg(4) and iconst(1) + isub(3), therefore tie.
I think the tie breaker chooses 0 - x afterward.
There was a problem hiding this comment.
Interesting. Probably we should adjust the cost of ineg: on all CPUs I'm aware of, a unary integer negation operator has the same cost as other ALU ops (1 cycle) so it should win against a const materialization plus an ALU op. Can you bundle that change in here and see if it fixes this regression?
There was a problem hiding this comment.
I adjusted ineg to have same cost with other ALU ops(cost = 3). I guess all affected test cases now produce ineg.
29006dc to
d3913af
Compare
|
@myunbin it looks like there is a verifier failure now -- could you take a look? |
|
@cfallin I found two issues.
log
|
c155127 to
73ee464
Compare
Add mid-end optimization rules:
(~x | y) ^ x --> ~(x & y)(~x OP y) ^ (~y OP x) --> x ^ y, whereOP = {&, |}(~x | y) & (~y | x) --> ~(x ^ y)max(x, y) OP min(x, y) --> x OP y, whereOP = {&, |, ^}max(~x, ~y) --> ~min(x, y)min(~x, ~y) --> ~max(x, y)~max(~x, y) --> min(x, ~y)~min(~x, y) --> max(x, ~y)-(x & y) + x --> x & ~y(~x & y) + (~y & x) --> x ^ y(-x) - (~x) --> 1~x + C --> (C - 1) - x(x + C) ^ -1 --> (-(C + 1)) - x(x | C) - C --> x & ~C(x | C) ^ (y | C) --> (x ^ y) & ~C(x | C) ^ (y ^ C) --> (x & ~C) ^ y(x << 1) * C --> x * (2 * C)~rotl(~x, k) --> rotl(x, k)~rotr(~x, k) --> rotr(x, k)(x << 1) == x --> x == 0(x >>u 1) == x --> x == 0(~x & y) == y --> (x & y) == 0~x == (~x | y) --> (x & y) == 0umax(x, y) OP 0 --> (x | y) OP 0, whereOP = {==, !=}umax(x, y) OP umin(x, y) --> x OP y, whereOP = {==, !=}(x >=s y) & (y >=s x) --> x == y(x >=u y) & (y >=u x) --> x == yselect(c, x, y) == select(c, y, x) --> x == yselect(x == 0, -x, x) --> x, and correspondingx != 0select(x == 0, 0, x OP y) --> x OP y, whereOP = {&, *}, and correspondingx != 0~select(c, C1, C2) --> select(c, ~C1, ~C2)-select(c, C1, C2) --> select(c, -C1, -C2)Thanks!