Skip to content

Conversation

@anematode
Copy link
Contributor

Fixes #144857 . I can create a test if desired, but I think the fix is trivial enough.

image

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 20, 2025

@llvm/pr-subscribers-clang

Author: Timothy Herchen (anematode)

Changes

Fixes #144857 . I can create a test if desired, but I think the fix is trivial enough.

<img width="805" height="105" alt="image" src="https://github.com/user-attachments/assets/aaee8e5f-6e65-4f04-b8b9-e4ae1434d958" />


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

1 Files Affected:

  • (modified) clang/lib/Sema/SemaX86.cpp (+5)
diff --git a/clang/lib/Sema/SemaX86.cpp b/clang/lib/Sema/SemaX86.cpp
index 5c149bdec7073..6bb3558972126 100644
--- a/clang/lib/Sema/SemaX86.cpp
+++ b/clang/lib/Sema/SemaX86.cpp
@@ -954,6 +954,11 @@ bool SemaX86::CheckBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
     l = 0;
     u = 15;
     break;
+  case X86::BI__builtin_ia32_prefetchi:
+    i = 1;
+    l = 2; // _MM_HINT_T1
+    u = 3; // _MM_HINT_T0
+    break;
   }
 
   // Note that we don't force a hard error on the range check here, allowing

@llvmbot
Copy link
Member

llvmbot commented Jul 20, 2025

@llvm/pr-subscribers-backend-x86

Author: Timothy Herchen (anematode)

Changes

Fixes #144857 . I can create a test if desired, but I think the fix is trivial enough.

<img width="805" height="105" alt="image" src="https://github.com/user-attachments/assets/aaee8e5f-6e65-4f04-b8b9-e4ae1434d958" />


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

1 Files Affected:

  • (modified) clang/lib/Sema/SemaX86.cpp (+5)
diff --git a/clang/lib/Sema/SemaX86.cpp b/clang/lib/Sema/SemaX86.cpp
index 5c149bdec7073..6bb3558972126 100644
--- a/clang/lib/Sema/SemaX86.cpp
+++ b/clang/lib/Sema/SemaX86.cpp
@@ -954,6 +954,11 @@ bool SemaX86::CheckBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
     l = 0;
     u = 15;
     break;
+  case X86::BI__builtin_ia32_prefetchi:
+    i = 1;
+    l = 2; // _MM_HINT_T1
+    u = 3; // _MM_HINT_T0
+    break;
   }
 
   // Note that we don't force a hard error on the range check here, allowing

@phoebewang
Copy link
Contributor

Thanks for the patch! You can add a test case for it like clang/test/CodeGen/X86/sm3-error.c

@RKSimon RKSimon requested a review from phoebewang July 21, 2025 07:29
@anematode
Copy link
Contributor Author

done :)

@anematode anematode force-pushed the prefetchi-invalid-arg branch 3 times, most recently from 76a7a50 to 8cfa0f9 Compare July 22, 2025 05:34
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.

@anematode
Copy link
Contributor Author

hmmmm why did it fail

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.

Please check test failures.

Comment on lines 18 to 20
Copy link
Contributor

Choose a reason for hiding this comment

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

The test needs to be in a seperate file.

@anematode anematode force-pushed the prefetchi-invalid-arg branch from 8cfa0f9 to 8f27a35 Compare July 22, 2025 05:58
Comment on lines 5 to 7
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

@anematode anematode force-pushed the prefetchi-invalid-arg branch from 8f27a35 to d6b0822 Compare July 22, 2025 06:09
@anematode
Copy link
Contributor Author

Sorry about that, should work now...

@anematode anematode force-pushed the prefetchi-invalid-arg branch from d6b0822 to fd1bba6 Compare July 22, 2025 06:20
@phoebewang phoebewang merged commit e644f5f into llvm:main Jul 22, 2025
9 checks passed
Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

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

This requires a release note, especially because it fixes a bug.

#include <immintrin.h>

void test_invalid_prefetchi(void* p) {
__builtin_ia32_prefetchi(p, 1); // expected-error {{argument value 1 is outside the valid range [2, 3]}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have a lower and upper range, testing should validate both. Tests should be as complete, especially when it is apparent and to prevent regression in behavior in the future due to new changes.

@phoebewang
Copy link
Contributor

This requires a release note, especially because it fixes a bug.

We don't change the intrinsic behavior and bug fixes usually don't need a release note. It's only needed when backporting to release branch.

mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
…49745)

Fixes llvm#144857 . I can create
a test if desired, but I think the fix is trivial enough.

<img width="805" height="105" alt="image"
src="https://github.com/user-attachments/assets/aaee8e5f-6e65-4f04-b8b9-e4ae1434d958"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[llvm] LLVM backend crashes when using __builtin_ia32_prefetchi

4 participants