[PATCH] D106210: [MS] Preserve base register %esi around movs[bwl]

2021-07-18 Thread namazso via Phabricator via cfe-commits
namazso added a comment.

i'd prefer it as just namazso with email ad...@namazso.eu


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106210/new/

https://reviews.llvm.org/D106210

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106210: [MS] Preserve base register %esi around movs[bwl]

2021-07-17 Thread namazso via Phabricator via cfe-commits
namazso added a comment.

I don't have commit access, could someone commit this for me? Thanks in advance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106210/new/

https://reviews.llvm.org/D106210

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106210: [MS] Preserve base register %esi around movs[bwl]

2021-07-17 Thread namazso via Phabricator via cfe-commits
namazso updated this revision to Diff 359550.
namazso added a comment.

fix linter warnings, update tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106210/new/

https://reviews.llvm.org/D106210

Files:
  clang/lib/Headers/intrin.h
  clang/test/CodeGen/ms-intrinsics.c


Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -36,7 +36,7 @@
   return __movsb(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsb
-// CHECK-I386:   call { i8*, i8*, i32 } asm sideeffect "rep movsb", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* 
%Src, i32 %Count)
+// CHECK-I386:   tail call { i8*, i8*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsb\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
@@ -62,7 +62,7 @@
   return __movsw(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsw
-// CHECK-I386:   call { i16*, i16*, i32 } asm sideeffect "rep movsw", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i16* %Dest, 
i16* %Src, i32 %Count)
+// CHECK-I386:   tail call { i16*, i16*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsw\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i16* %Dest, i16* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
@@ -88,7 +88,7 @@
   return __movsd(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsd
-// CHECK-I386:   call { i32*, i32*, i32 } asm sideeffect "rep movsl", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %Dest, 
i32* %Src, i32 %Count)
+// CHECK-I386:   tail call { i32*, i32*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsl\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %Dest, i32* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
Index: clang/lib/Headers/intrin.h
===
--- clang/lib/Headers/intrin.h
+++ clang/lib/Headers/intrin.h
@@ -451,24 +451,47 @@
 static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
   unsigned char const *__src,
   size_t __n) {
-  __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
-   : : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsb"
+   : "+D"(__dst), "+S"(__src), "+c"(__n)
+   :
+   : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsb\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
   unsigned long const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsl"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsl\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
   unsigned short const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsw"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsw\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
   unsigned long __x,


Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -36,7 +36,7 @@
   return __movsb(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsb
-// CHECK-I386:   call { i8*, i8*, i32 } asm sideeffect "rep movsb", "={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* %Src, i32 %Count)
+// CHECK-I386:   tail call { i8*, i8*, i32 } asm sideeffect "xchg %esi, $1\0Arep movsb\0Axchg %esi, $1", 

[PATCH] D106210: [MS] Preserve base register %esi around movs[bwl]

2021-07-16 Thread namazso via Phabricator via cfe-commits
namazso created this revision.
namazso added a project: clang.
namazso requested review of this revision.
Herald added a subscriber: cfe-commits.

fix for behavior reported in https://bugs.llvm.org/show_bug.cgi?id=51100 
workaround for root cause https://bugs.llvm.org/show_bug.cgi?id=16830


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106210

Files:
  clang/lib/Headers/intrin.h


Index: clang/lib/Headers/intrin.h
===
--- clang/lib/Headers/intrin.h
+++ clang/lib/Headers/intrin.h
@@ -451,24 +451,35 @@
 static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
   unsigned char const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
: : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsb\nxchg %%esi, %1" : 
"+D"(__dst), "+r"(__src), "+c"(__n)
+   : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
   unsigned long const *__src,
   size_t __n) {
-  __asm__ __volatile__("rep movsl"
-   : "+D"(__dst), "+S"(__src), "+c"(__n)
-   :
-   : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsl" : "+D"(__dst), "+S"(__src), "+c"(__n)
+   : : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsl\nxchg %%esi, %1" : 
"+D"(__dst), "+r"(__src), "+c"(__n)
+   : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
   unsigned short const *__src,
   size_t __n) {
-  __asm__ __volatile__("rep movsw"
-   : "+D"(__dst), "+S"(__src), "+c"(__n)
-   :
-   : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsw" : "+D"(__dst), "+S"(__src), "+c"(__n)
+   : : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsw\nxchg %%esi, %1" : 
"+D"(__dst), "+r"(__src), "+c"(__n)
+   : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
   unsigned long __x,


Index: clang/lib/Headers/intrin.h
===
--- clang/lib/Headers/intrin.h
+++ clang/lib/Headers/intrin.h
@@ -451,24 +451,35 @@
 static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
   unsigned char const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
: : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsb\nxchg %%esi, %1" : "+D"(__dst), "+r"(__src), "+c"(__n)
+   : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
   unsigned long const *__src,
   size_t __n) {
-  __asm__ __volatile__("rep movsl"
-   : "+D"(__dst), "+S"(__src), "+c"(__n)
-   :
-   : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsl" : "+D"(__dst), "+S"(__src), "+c"(__n)
+   : : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsl\nxchg %%esi, %1" : "+D"(__dst), "+r"(__src), "+c"(__n)
+   : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
   unsigned short const *__src,
   size_t __n) {
-  __asm__ __volatile__("rep movsw"
-   : "+D"(__dst), "+S"(__src), "+c"(__n)
-   :
-   : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsw" : "+D"(__dst), "+S"(__src), "+c"(__n)
+   : : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsw\nxchg %%esi, %1" : "+D"(__dst), "+r"(__src), "+c"(__n)
+   : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
   unsigned long __x,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits