This is an archive of the discontinued LLVM Phabricator instance.

[X86] Report error if the amx enabled on the non-64-bits target
AbandonedPublic

Authored by LiuChen3 on Aug 3 2022, 6:01 PM.

Details

Summary

For now we check if the amx intrinsics used on 64-bits target. This
check is not accurate.

Diff Detail

Event Timeline

LiuChen3 created this revision.Aug 3 2022, 6:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 6:01 PM
LiuChen3 requested review of this revision.Aug 3 2022, 6:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 6:01 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
pengfei accepted this revision.Aug 4 2022, 5:44 AM
pengfei added a subscriber: aaron.ballman.

LGTM, but maybe wait one day or two for other FE folks' opinions. @aaron.ballman

This revision is now accepted and ready to land.Aug 4 2022, 5:44 AM

I think the precommit CI failures might be relevant here -- can you double-check those?

How does this interact with -march=native -m32. Won't that pick up the amx flag from CPUID?

craig.topper requested changes to this revision.Aug 4 2022, 9:05 AM
This revision now requires changes to proceed.Aug 4 2022, 9:05 AM

How does this interact with -march=native -m32. Won't that pick up the amx flag from CPUID?

I think the precommit CI failures might be relevant here -- can you double-check those?

Yes. This test is only supported on amdgpu-registered-target so I didn't catch this fail on my local machine. Thanks for point out.

How does this interact with -march=native -m32. Won't that pick up the amx flag from CPUID?

Good point. I will continue the work.

LiuChen3 updated this revision to Diff 450702.Aug 7 2022, 11:00 PM

fix lit fail and handle '-march=native'

LiuChen3 updated this revision to Diff 450724.Aug 8 2022, 1:17 AM

change the error report

craig.topper added inline comments.Aug 8 2022, 10:46 AM
clang/lib/Driver/ToolChains/Arch/X86.cpp
133

This looks like it would trigger an error with -march=native -m32 on a cpu with amx? Why is that a desirable behavior? The compiler user has done nothing wrong. What are they supposed to do to avoid the error?

What problem are we trying to solve here? CPUID reports AMX as supported even in 32-bit mode. Why can't the user pass it to the compiler?

What problem are we trying to solve here? CPUID reports AMX as supported even in 32-bit mode. Why can't the user pass it to the compiler?

I thought AMX is only supported on 64-bit mode. It seems I was wrong. So for now just reporting an error to intrinsics is enough. Thanks.

LiuChen3 abandoned this revision.Aug 10 2022, 8:04 PM

I have the same impression. I checked ISE says AMX instructions are N.E. on 32-bit mode. And seems Linux Kernel only enables AMX on 64-bit too https://lwn.net/ml/linux-kernel/20210730145957.7927-22-chang.seok.bae@intel.com/#t

Yes AMX is only supported in 64-bit mode but I doubt CPUID checks which mode the program is running in.

Yes AMX is only supported in 64-bit mode but I doubt CPUID checks which mode the program is running in.

I guess HasAMXSave is false on 32-bit mode https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/Host.cpp#L1800. But I don't have the environment to check it.

Yes AMX is only supported in 64-bit mode but I doubt CPUID checks which mode the program is running in.

I guess HasAMXSave is false on 32-bit mode https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/Host.cpp#L1800. But I don't have the environment to check it.

I found it. The XFEATURE_MASK_XTILE in Kernel is the same as HasAMXSave in compiler: https://lwn.net/ml/linux-kernel/20210710130313.5072-20-chang.seok.bae@intel.com/
So these features bits are true only on 64-bit mode.

Yes AMX is only supported in 64-bit mode but I doubt CPUID checks which mode the program is running in.

I guess HasAMXSave is false on 32-bit mode https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/Host.cpp#L1800. But I don't have the environment to check it.

I found it. The XFEATURE_MASK_XTILE in Kernel is the same as HasAMXSave in compiler: https://lwn.net/ml/linux-kernel/20210710130313.5072-20-chang.seok.bae@intel.com/
So these features bits are true only on 64-bit mode.

Is it cleared when running a 32-bit binary on a 64-bit kernel?

Yes AMX is only supported in 64-bit mode but I doubt CPUID checks which mode the program is running in.

I guess HasAMXSave is false on 32-bit mode https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/Host.cpp#L1800. But I don't have the environment to check it.

I found it. The XFEATURE_MASK_XTILE in Kernel is the same as HasAMXSave in compiler: https://lwn.net/ml/linux-kernel/20210710130313.5072-20-chang.seok.bae@intel.com/
So these features bits are true only on 64-bit mode.

Is it cleared when running a 32-bit binary on a 64-bit kernel?

No, a 32-bit binary gets the same CR0 as 64-bit on a 64-bit kernel. Actually, it's compiler to get the CR0 rather than the binary it builds. It should be rare to run 32-bit compiler on 64-bit kernel.
So you are right. No matter 32 or 64 bits compiler, when it builds a binary with -m32 on 64-bit kernel with -march=native, it always sets AMX features. Maybe we should reset them to false when compile for 32-bit?