Skip to content

Commit 522d55b

Browse files
[x86-64] Fix improper instruction selection for subtraction (#510)
1 parent af22f8c commit 522d55b

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

aeneas/src/x86-64/SsaX86_64Gen.v3

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ class SsaX86_64Gen extends SsaMachGen {
123123
}
124124
IntSub => {
125125
var yval = m.intbinop(i);
126-
if (MATCH_NEG && m.xconst && m.xint == 0) return emit1(I_NEGQ | (AM_OP << AM_SHIFT), ovwReg(i, m.y));
126+
if (MATCH_NEG && m.xconst &&
127+
((m.inttype.width <= 32 && m.xint == 0) || (m.inttype.width > 32 && m.xlong == 0))) {
128+
return emit1(I_NEGQ | (AM_OP << AM_SHIFT), ovwReg(i, m.y));
129+
}
127130
emitIntBinop(I_SUBD, i);
128131
}
129132
IntMul => {

test/core/int_sub05.v3

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@execute 0=1; 1=0
2+
component int_sub05 {
3+
def main(a: int) -> int {
4+
return 1 - a;
5+
}
6+
}

test/core/long_sub01.v3

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@execute (0,1)=-1; (1,-1)=2; (-200,13)=-213
2+
component long_sub01 {
3+
def main(a: int, b: int) -> int { return int.view(long.!(a) - long.!(b)); }
4+
}

test/core/long_sub02.v3

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@execute 1=0; 0=1
2+
component long_sub02 {
3+
def main(a: int) -> int { return int.view(1 - long.!(a)); }
4+
}

test/core/long_sub03.v3

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@execute 1=-1; 0=0
2+
component long_sub03 {
3+
def main(a: int) -> int { return int.view(0 - long.!(a)); }
4+
}

0 commit comments

Comments
 (0)