Browse Source

* fix abs() intrinsic optimisation, resolves #37301

git-svn-id: trunk@45732 -
florian 5 years ago
parent
commit
3caacc529a
3 changed files with 20 additions and 6 deletions
  1. 1 0
      .gitattributes
  2. 6 6
      compiler/x86/aoptx86.pas
  3. 13 0
      tests/webtbs/tw37301.pp

+ 1 - 0
.gitattributes

@@ -18348,6 +18348,7 @@ tests/webtbs/tw37228.pp svneol=native#text/plain
 tests/webtbs/tw37254.pp svneol=native#text/pascal
 tests/webtbs/tw37261.pp svneol=native#text/pascal
 tests/webtbs/tw37272a.pp svneol=native#text/pascal
+tests/webtbs/tw37301.pp svneol=native#text/pascal
 tests/webtbs/tw3742.pp svneol=native#text/plain
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain

+ 6 - 6
compiler/x86/aoptx86.pas

@@ -4322,14 +4322,14 @@ unit aoptx86;
                               with taicpu(hp4).oper[OperIdx]^ do
                                 case typ of
                                   top_reg:
-                                    if reg = NR_EDX then
-                                      reg := NR_EAX;
+                                    if getsupreg(reg) = RS_EDX then
+                                      reg := newreg(R_INTREGISTER,RS_EAX,getsubreg(reg));
                                   top_ref:
                                     begin
-                                      if ref^.base = NR_EDX then
-                                        ref^.base := NR_EAX;
-                                      if ref^.index = NR_EDX then
-                                        ref^.index := NR_EAX;
+                                      if getsupreg(reg) = RS_EDX then
+                                        ref^.base := newreg(R_INTREGISTER,RS_EAX,getsubreg(reg));
+                                      if getsupreg(reg) = RS_EDX then
+                                        ref^.index := newreg(R_INTREGISTER,RS_EAX,getsubreg(reg));
                                     end;
                                   else
                                     ;

+ 13 - 0
tests/webtbs/tw37301.pp

@@ -0,0 +1,13 @@
+{ %OPT=-O- -O1 }
+program testbug;
+{$mode objfpc}{$h+}
+var
+  i: Integer;
+  b: Byte;
+  w: Word;
+begin
+  i := 53;
+  b := 0;
+  w := abs(i-b);
+  WriteLn(w);
+end.