[LLVMdev] [PATCH] Detect Haswell subarchitecture (i.e. using -march=native)

Adam Strzelecki ono at java.pl
Thu Sep 12 09:28:14 PDT 2013


> That's far more worrying to me than not being able to detect Haswell.
> I can't reproduce the problem here at the moment: both debug and
> release builds give identical assembly for Host.cpp.

OK. I know the reason you cannot reproduce it, before posting the patch I've decided to check for AVX before checking AVX2, just not to cpuid AVX2 when we don't have AVX1 anyway.

So the problem exists with following predicate: (1)
  bool HasAVX2 = !GetX86CpuIDAndInfo(0x7, &EAX, &EBX, &ECX, &EDX) &&
                 (EBX & 0x20);

However it is working absolutely fine if I add "volatile": (2)
  volatile bool HasAVX2 = !GetX86CpuIDAndInfo(0x7, &EAX, &EBX, &ECX, &EDX) &&
                          (EBX & 0x20);

Or add extra check for HasAVX: (3)
  bool HasAVX2 = HasAVX && !GetX86CpuIDAndInfo(0x7, &EAX, &EBX, &ECX, &EDX) &&
                 (EBX & 0x20);

Attaching object files related to all of these cases below.

Also attaching patch that removes volatile, but leaves HasAVX check that makes the code run fine here.

My platform is Ubuntu 12.04 LTS 64-bit & i7-4470k.

llvm[1]: Compiling Host.cpp for Release build
if  clang++ -I/home/ono/Documents/llvm/include -I/home/ono/Documents/llvm/lib/Support -I/tmp/llvm.q35LGwjHmR/include -I/tmp/llvm.q35LGwjHmR/lib/Support  -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -Woverloaded-virtual -Wcast-qual    -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcovered-switch-default -Wno-uninitialized -Wno-missing-field-initializers -c -MMD -MP -MF "/tmp/llvm.q35LGwjHmR/lib/Support/Release/Host.d.tmp" -MT "/tmp/llvm.q35LGwjHmR/lib/Support/Release/Host.o" -MT "/tmp/llvm.q35LGwjHmR/lib/Support/Release/Host.d" /home/ono/Documents/llvm/lib/Support/Host.cpp -o /tmp/llvm.q35LGwjHmR/lib/Support/Release/Host.o ; \
	        then /bin/mv -f "/tmp/llvm.q35LGwjHmR/lib/Support/Release/Host.d.tmp" "/tmp/llvm.q35LGwjHmR/lib/Support/Release/Host.d"; else /bin/rm "/tmp/llvm.q35LGwjHmR/lib/Support/Release/Host.d.tmp"; exit 1; fi

Regards,
-- 
Adam Strzelecki | nanoant.com | twitter.com/nanoant

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Host-objects.tbz2
Type: application/octet-stream
Size: 6366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130912/6c851eb1/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-detect-haswell-r2.patch
Type: application/octet-stream
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130912/6c851eb1/attachment-0001.obj>


More information about the llvm-dev mailing list