Skip to content

Simple check to ignore Inline asm fwait insertion #101686

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

Merged

Conversation

Temperature-block
Copy link
Contributor

@Temperature-block Temperature-block commented Aug 2, 2024

Just a simple check to ignore Inline asm fwait insertion

Fixes #101613

Copy link

github-actions bot commented Aug 2, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@Temperature-block Temperature-block changed the title Fixes #101613 Fixes #101613 simple check to ignore Inline asm fwait insertion Aug 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 2, 2024

@llvm/pr-subscribers-backend-x86

Author: Temperatureblock (Temperature-block)

Changes

Just a simple check to ignore Inline asm fwait insertion


Full diff: https://github.com/llvm/llvm-project/pull/101686.diff

2 Files Affected:

  • (modified) llvm/lib/Target/X86/X86InsertWait.cpp (+3-2)
  • (modified) llvm/test/CodeGen/X86/pr59305.ll (-3)
diff --git a/llvm/lib/Target/X86/X86InsertWait.cpp b/llvm/lib/Target/X86/X86InsertWait.cpp
index 69a3d32a93149..0a1810a3da711 100644
--- a/llvm/lib/Target/X86/X86InsertWait.cpp
+++ b/llvm/lib/Target/X86/X86InsertWait.cpp
@@ -103,8 +103,9 @@ bool WaitInsert::runOnMachineFunction(MachineFunction &MF) {
 
   for (MachineBasicBlock &MBB : MF) {
     for (MachineBasicBlock::iterator MI = MBB.begin(); MI != MBB.end(); ++MI) {
-      // Jump non X87 instruction.
-      if (!X86::isX87Instruction(*MI))
+
+      // Jump non X87 instruction and Inline asm.
+      if (!X86::isX87Instruction(*MI) || MI->isInlineAsm())
         continue;
       // If the instruction instruction neither has float exception nor is
       // a load/store instruction, or the instruction is x87 control
diff --git a/llvm/test/CodeGen/X86/pr59305.ll b/llvm/test/CodeGen/X86/pr59305.ll
index 46c9da5a51939..5185f1429f289 100644
--- a/llvm/test/CodeGen/X86/pr59305.ll
+++ b/llvm/test/CodeGen/X86/pr59305.ll
@@ -81,20 +81,17 @@ define double @bar(double %0) #0 {
 ; X64-NEXT:    #APP
 ; X64-NEXT:    ldmxcsr 0
 ; X64-NEXT:    #NO_APP
-; X64-NEXT:    wait
 ; X64-NEXT:    movsd {{.*#+}} xmm2 = [1.0E+0,0.0E+0]
 ; X64-NEXT:    movapd %xmm2, %xmm3
 ; X64-NEXT:    divsd %xmm0, %xmm3
 ; X64-NEXT:    #APP
 ; X64-NEXT:    ldmxcsr 0
 ; X64-NEXT:    #NO_APP
-; X64-NEXT:    wait
 ; X64-NEXT:    movapd %xmm2, %xmm1
 ; X64-NEXT:    divsd %xmm0, %xmm1
 ; X64-NEXT:    #APP
 ; X64-NEXT:    ldmxcsr 0
 ; X64-NEXT:    #NO_APP
-; X64-NEXT:    wait
 ; X64-NEXT:    divsd %xmm0, %xmm2
 ; X64-NEXT:    movapd %xmm3, %xmm0
 ; X64-NEXT:    callq fma@PLT

@RKSimon RKSimon changed the title Fixes #101613 simple check to ignore Inline asm fwait insertion Simple check to ignore Inline asm fwait insertion Aug 6, 2024
@RKSimon RKSimon requested review from phoebewang and RKSimon August 6, 2024 12:46
if (!X86::isX87Instruction(*MI))

// Jump non X87 instruction and Inline asm.
if (!X86::isX87Instruction(*MI) || MI->isInlineAsm())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the check in isX87Instruction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops my bad I accidentally force pushed incomplete changes, will update today sorry for any confusions.

@Temperature-block Temperature-block force-pushed the ignore_inlineasm_X87Insertwait branch 2 times, most recently from a3eb806 to 9d43e74 Compare August 7, 2024 17:06
@phoebewang
Copy link
Contributor

Pre-checkin failure is relevant, please check it.

Changes
  X86InstrInfo.cpp
  updated with check to ignore inlineasm
  pr59305.ll
  Test case fix
@Temperature-block Temperature-block force-pushed the ignore_inlineasm_X87Insertwait branch from 9d43e74 to 1324a5f Compare August 12, 2024 12:12
@Temperature-block
Copy link
Contributor Author

@phoebewang
updated with test-case change, wait needs to be inserted before final instruction in series of X87 instructions or when next instruction is a Nonwaitcontrol instruction which may reset the status registers
Please do let me know if something is amiss from my side,
Thank you

Copy link
Contributor

@phoebewang phoebewang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@phoebewang phoebewang merged commit db3c3fc into llvm:main Aug 12, 2024
8 checks passed
Copy link

@Temperature-block Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline ASM not ignored in Insertwait pass
3 participants