[PATCH] D142477: [X86] Ensure the _mm_test_all_ones macro does not reuse argument (PR60006)
Simon Pilgrim via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 24 07:55:03 PST 2023
RKSimon created this revision.
RKSimon added reviewers: pengfei, craig.topper.
Herald added a project: All.
RKSimon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The macro `_mm_test_all_ones(V)` was defined as `_mm_testc_si128((V), _mm_cmpeq_epi32((V), (V)))` - which could cause side effects depending on the source of the V value.
The `_mm_cmpeq_epi32((V), (V))` trick was just to materialize an all-ones value, which can be more safely generated with `_mm_set1_epi32(-1)` .
Fixes #60006
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142477
Files:
clang/lib/Headers/smmintrin.h
clang/test/CodeGen/X86/sse41-builtins.c
Index: clang/test/CodeGen/X86/sse41-builtins.c
===================================================================
--- clang/test/CodeGen/X86/sse41-builtins.c
+++ clang/test/CodeGen/X86/sse41-builtins.c
@@ -401,3 +401,13 @@
// CHECK: extractelement <4 x float> %{{.*}}, i32 0
return _mm_round_ps(a, 0)[0];
}
+
+// Ensure _mm_test_all_ones macro doesn't reuse argument
+__m128i expensive_call();
+int pr60006() {
+ // CHECK-LABEL: pr60006
+ // CHECK: call {{.*}} @expensive_call
+ // CHECK-NOT: call {{.*}} @expensive_call
+ // CHECK: call i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
+ return _mm_test_all_ones(expensive_call());
+}
Index: clang/lib/Headers/smmintrin.h
===================================================================
--- clang/lib/Headers/smmintrin.h
+++ clang/lib/Headers/smmintrin.h
@@ -1145,7 +1145,7 @@
/// A 128-bit integer vector containing the bits to be tested.
/// \returns TRUE if the bits specified in the operand are all set to 1; FALSE
/// otherwise.
-#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_cmpeq_epi32((V), (V)))
+#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_set1_epi32(-1))
/// Tests whether the specified bits in a 128-bit integer vector are
/// neither all zeros nor all ones.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142477.491800.patch
Type: text/x-patch
Size: 1287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230124/9ceb56b8/attachment.bin>
More information about the cfe-commits
mailing list