Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang -march=x86-64 is different from the generic x86-64 tuning #54472

Closed
zmodem opened this issue Mar 21, 2022 · 3 comments
Closed

clang -march=x86-64 is different from the generic x86-64 tuning #54472

zmodem opened this issue Mar 21, 2022 · 3 comments
Labels
backend:X86 question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@zmodem
Copy link
Collaborator

zmodem commented Mar 21, 2022

I was wondering why clang seems to prefer add $1 over inc when building Chromium, even though 0b7669f made inc no longer considered slow in the generic tuning.

It seems it's because we pass -march=x86-64. Which is surprising to me, because that sounds generic enough.

Consider:

$ cat /tmp/a.cc
bool f(unsigned *i) {
      return ++(*i) == 0;
}

$ clang -O2 -S -o - /tmp/a.cc -target x86_64-unknown-linux-gnu
[...]
        incl    (%rdi)
        sete    %al
        retq

$ clang -O2 -S -o - /tmp/a.cc -target x86_64-unknown-linux-gnu -march=x86-64
[...]
        addl    $1, (%rdi)
        sete    %al
        retq

Is this working as intended?

Adding -mtune=generic brings back the inc instruction:

$ clang -O2 -S -o - /tmp/a.cc -target x86_64-unknown-linux-gnu -march=x86-64 -mtune=generic
[...]
        incl    (%rdi)
        sete    %al
        retq
@phoebewang
Copy link
Contributor

This is intended. generic aims for an average of popular targets. So it will change over time. x86-64 represents a minimal feature collections, which should be only used to be compatible with very old 64 bit targets. It's recommended to try with -march=x86-64-v2 or above based on your targets. Or simply not to use -march=x86-64.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 21, 2022

@llvm/issue-subscribers-backend-x86

@zmodem
Copy link
Collaborator Author

zmodem commented Mar 21, 2022

Thanks, I'll look into why we're passing the flag in the first place. Closing since it sounds like clang is working as intended.

(http://crbug.com/1308407 for anyone interested)

@zmodem zmodem closed this as completed Mar 21, 2022
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Mar 21, 2022
Kwizatz pushed a commit to AeonGames/build that referenced this issue Apr 10, 2022
In addition to the linked bug, see also
llvm/llvm-project#54472 (comment)

Bug: 1308407
Change-Id: I100f256641487994187b2584f741409f6ff2f393
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3572249
Commit-Queue: Nico Weber <thakis@chromium.org>
Auto-Submit: Nico Weber <thakis@chromium.org>
Reviewed-by: Hans Wennborg <hans@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/main@{#989565}
NOKEYCHECK=True
GitOrigin-RevId: de2f63196691e894e6c0c311208995bee8306618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

4 participants