[llvm-branch-commits] [cfe-branch] r344923 - Merging r344824:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Oct 22 10:31:01 PDT 2018


Author: tstellar
Date: Mon Oct 22 10:31:01 2018
New Revision: 344923

URL: http://llvm.org/viewvc/llvm-project?rev=344923&view=rev
Log:
Merging r344824:

------------------------------------------------------------------------
r344824 | ctopper | 2018-10-19 18:30:00 -0700 (Fri, 19 Oct 2018) | 14 lines

[X86] When checking the bits in cpu_features for function multiversioning dispatcher in the resolver, make sure all the required bits are set. Not just one of them

Summary:
The multiversioning code repurposed the code from __builtin_cpu_supports for checking if a single feature is enabled. That code essentially performed (_cpu_features & (1 << C)) != 0. But with the multiversioning path, the mask is no longer guaranteed to be a power of 2. So we return true anytime any one of the bits in the mask is set not just all of the bits.

The correct check is (_cpu_features & mask) == mask

Reviewers: erichkeane, echristo

Reviewed By: echristo

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D53460
------------------------------------------------------------------------

Modified:
    cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp
    cfe/branches/release_70/test/CodeGen/attr-target-mv.c
    cfe/branches/release_70/test/CodeGen/builtin-cpu-supports.c

Modified: cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp?rev=344923&r1=344922&r2=344923&view=diff
==============================================================================
--- cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp Mon Oct 22 10:31:01 2018
@@ -8952,9 +8952,9 @@ llvm::Value *CodeGenFunction::EmitX86Cpu
       Builder.CreateAlignedLoad(CpuFeatures, CharUnits::fromQuantity(4));
 
   // Check the value of the bit corresponding to the feature requested.
-  Value *Bitset = Builder.CreateAnd(
-      Features, llvm::ConstantInt::get(Int32Ty, FeaturesMask));
-  return Builder.CreateICmpNE(Bitset, llvm::ConstantInt::get(Int32Ty, 0));
+  Value *Mask = Builder.getInt32(FeaturesMask);
+  Value *Bitset = Builder.CreateAnd(Features, Mask);
+  return Builder.CreateICmpEQ(Bitset, Mask);
 }
 
 Value *CodeGenFunction::EmitX86CpuInit() {

Modified: cfe/branches/release_70/test/CodeGen/attr-target-mv.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/test/CodeGen/attr-target-mv.c?rev=344923&r1=344922&r2=344923&view=diff
==============================================================================
--- cfe/branches/release_70/test/CodeGen/attr-target-mv.c (original)
+++ cfe/branches/release_70/test/CodeGen/attr-target-mv.c Mon Oct 22 10:31:01 2018
@@ -70,6 +70,22 @@ void bar4() {
 // CHECK: ret void ()* @foo_decls.sse4.2
 // CHECK: ret void ()* @foo_decls
 
+// CHECK: define void @bar4()
+// CHECK: call void @foo_multi.ifunc()
+
+// CHECK: define void ()* @foo_multi.resolver() comdat
+// CHECK: and i32 %{{.*}}, 4352
+// CHECK: icmp eq i32 %{{.*}}, 4352
+// CHECK: ret void ()* @foo_multi.fma4_sse4.2
+// CHECK: icmp eq i32 %{{.*}}, 12
+// CHECK: and i32 %{{.*}}, 4352
+// CHECK: icmp eq i32 %{{.*}}, 4352
+// CHECK: ret void ()* @foo_multi.arch_ivybridge_fma4_sse4.2
+// CHECK: and i32 %{{.*}}, 768
+// CHECK: icmp eq i32 %{{.*}}, 768
+// CHECK: ret void ()* @foo_multi.avx_sse4.2
+// CHECK: ret void ()* @foo_multi
+
 // CHECK: declare i32 @foo.arch_sandybridge()
 
 // CHECK: define available_externally i32 @foo_inline.sse4.2()
@@ -88,4 +104,3 @@ void bar4() {
 // CHECK: define available_externally void @foo_multi.avx_sse4.2()
 // CHECK: define available_externally void @foo_multi.fma4_sse4.2()
 // CHECK: define available_externally void @foo_multi.arch_ivybridge_fma4_sse4.2()
-

Modified: cfe/branches/release_70/test/CodeGen/builtin-cpu-supports.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/test/CodeGen/builtin-cpu-supports.c?rev=344923&r1=344922&r2=344923&view=diff
==============================================================================
--- cfe/branches/release_70/test/CodeGen/builtin-cpu-supports.c (original)
+++ cfe/branches/release_70/test/CodeGen/builtin-cpu-supports.c Mon Oct 22 10:31:01 2018
@@ -14,7 +14,7 @@ int main() {
 
   // CHECK: [[LOAD:%[^ ]+]] = load i32, i32* getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, { i32, i32, i32, [1 x i32] }* @__cpu_model, i32 0, i32 3, i32 0)
   // CHECK: [[AND:%[^ ]+]] = and i32 [[LOAD]], 256
-  // CHECK: = icmp ne i32 [[AND]], 0
+  // CHECK: = icmp eq i32 [[AND]], 256
 
   return 0;
 }




More information about the llvm-branch-commits mailing list