summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-07-05 09:19:14 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-07-05 09:19:14 +0000
commita6b4cc49f19429b442d8dfbd834d2bd291a843b2 (patch)
tree9da6172a617370a3f417c604f8956a1b399cfd95
parentc06212c83b340c3e0398bfbb51e10a19fe48e0aa (diff)
downloadfpc-a6b4cc49f19429b442d8dfbd834d2bd291a843b2.tar.gz
* fix abs() intrinsic optimisation, resolves #37301
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@45732 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--compiler/x86/aoptx86.pas12
-rw-r--r--tests/webtbs/tw37301.pp13
2 files changed, 19 insertions, 6 deletions
diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas
index 063e72803f..7874a8db36 100644
--- a/compiler/x86/aoptx86.pas
+++ b/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
;
diff --git a/tests/webtbs/tw37301.pp b/tests/webtbs/tw37301.pp
new file mode 100644
index 0000000000..43c20f939d
--- /dev/null
+++ b/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.