-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][CodeGen] Add range metadata for atomic load of boolean type. #131476 #133546
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
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4581169
[clang][CodeGen] Added llvm ir pre-commit test.
janagor 852b691
[clang][CodeGen] Added `!range` metadata to atomic load for `bool`.
janagor e42772b
Updated codestyle.
janagor c95f16c
Refactored early returns into normal if statement.
janagor ecc0f40
Reverted adding `range!` metadata from 852b691fac48. Added `isSafeNUW…
janagor 97dc8df
Merge branch 'main' into add_range_metadata
janagor 91142fa
Merge branch 'main' into add_range_metadata
janagor 7e60e8f
fixup! Merge branch 'main' into add_range_metadata
janagor df9c2bc
Reverted to state before ecc0f4060b91.
janagor f25e687
Exposed `getRangeForLoadFromType` as a public method to support addin…
janagor a348252
Created helper function for calling `EmitScalarRangeCheck()` and addi…
janagor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -590,6 +590,29 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr *E, Address Dest, | |
| llvm::LoadInst *Load = CGF.Builder.CreateLoad(Ptr); | ||
| Load->setAtomic(Order, Scope); | ||
| Load->setVolatile(E->isVolatile()); | ||
|
|
||
| if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0) { | ||
| CGF.Builder.CreateStore(Load, Dest); | ||
| return; | ||
| } | ||
|
|
||
| QualType Ty = E->getValueType(); | ||
| if (!Ty->isBooleanType()) { | ||
| CGF.Builder.CreateStore(Load, Dest); | ||
| return; | ||
| } | ||
|
|
||
| llvm::MDBuilder MDHelper(CGF.getLLVMContext()); | ||
| llvm::APInt BooleanMin = llvm::APInt(CGF.getContext().getTypeSize(Ty), 0); | ||
| llvm::APInt BooleanEnd = llvm::APInt(CGF.getContext().getTypeSize(Ty), 2); | ||
|
|
||
| if (llvm::MDNode *RangeInfo = | ||
| MDHelper.createRange(BooleanMin, BooleanEnd)) { | ||
|
||
| Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo); | ||
| Load->setMetadata(llvm::LLVMContext::MD_noundef, | ||
| llvm::MDNode::get(CGF.getLLVMContext(), {})); | ||
| } | ||
|
|
||
| CGF.Builder.CreateStore(Load, Dest); | ||
| return; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // RUN: %clang_cc1 -triple riscv64 -O1 -emit-llvm %s -o - | FileCheck %s | ||
| #include <stdbool.h> | ||
|
|
||
| extern bool t1; | ||
| bool test1(void) { | ||
| // CHECK-LABEL: define{{.*}} i1 @test1 | ||
| // CHECK: load atomic i8, ptr @t1 monotonic, align 1, !range ![[$WS_RANGE:[0-9]*]], !noundef !{{[0-9]+}} | ||
| // CHECK-NEXT: trunc nuw i8 %{{.*}} to i1 | ||
| // CHECK-NEXT: ret i1 %{{.*}} | ||
| return __atomic_load_n(&t1, __ATOMIC_RELAXED); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an early return like this is weird; just stick a normal if statement around the code that creates the metadata.