- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
[llvm][opt][Transforms] Preserve AMDGPU atomic metadata #140314
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
          
     Closed
      
      
    
  
     Closed
                    Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      31ceada
              
                Do not drop atomic metadata when combining instructions.
              
              
                AlexVlx 9e7ca22
              
                Fix formatting.
              
              
                AlexVlx 8ea68b4
              
                Clean up test.
              
              
                AlexVlx c6cfed6
              
                Handle all cases.
              
              
                AlexVlx 401b882
              
                Fix formatting.
              
              
                AlexVlx c309620
              
                Intersection, not union.
              
              
                AlexVlx c724475
              
                Fix stray whitespace.
              
              
                AlexVlx 768c92e
              
                Merge branch 'main' of https://github.com/llvm/llvm-project into fix_…
              
              
                AlexVlx f3844ae
              
                Merge branch 'main' into fix_metadata_sinking
              
              
                AlexVlx f28e605
              
                Merge branch 'main' of https://github.com/llvm/llvm-project into fix_…
              
              
                AlexVlx 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
    
  
  
    
              
        
          
          
            42 changes: 42 additions & 0 deletions
          
          42 
        
  llvm/test/Transforms/SimplifyCFG/merge-amdgpu-atomic-md.ll
  
  
      
      
   
        
      
      
    
  
    
      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,42 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ;; Test to ensure that AMDGPU atomic related metadata is not dropped when | ||
| ;; instructions are sunk. Currently the metadata from the first instruction | ||
| ;; is kept, which prevents full loss of optimisation information. | ||
| 
     | 
||
| ; RUN: opt < %s -passes=simplifycfg -passes=simplifycfg -sink-common-insts -S | FileCheck %s | ||
                
      
                  AlexVlx marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| define amdgpu_kernel void @f(i1 %pred0, i1 %pred1, ptr captures(none) %p, double %d) local_unnamed_addr { | ||
| ; CHECK-LABEL: define amdgpu_kernel void @f( | ||
| ; CHECK-SAME: i1 [[PRED0:%.*]], i1 [[PRED1:%.*]], ptr captures(none) [[P:%.*]], double [[D:%.*]]) local_unnamed_addr { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: [[P_GLOBAL:%.*]] = addrspacecast ptr [[P]] to ptr addrspace(1) | ||
| ; CHECK-NEXT: [[BRMERGE:%.*]] = select i1 [[PRED0]], i1 true, i1 [[PRED1]] | ||
| ; CHECK-NEXT: br i1 [[BRMERGE]], label %[[IF_END_SINK_SPLIT:.*]], label %[[IF_END:.*]] | ||
| ; CHECK: [[IF_END_SINK_SPLIT]]: | ||
| ; CHECK-NEXT: [[TMP0:%.*]] = atomicrmw fadd ptr addrspace(1) [[P_GLOBAL]], double [[D]] monotonic, align 8, !amdgpu.no.fine.grained.memory [[META0:![0-9]+]], !amdgpu.no.remote.memory [[META0]] | ||
| ; CHECK-NEXT: br label %[[IF_END]] | ||
| ; CHECK: [[IF_END]]: | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| entry: | ||
| %p.global = addrspacecast ptr %p to ptr addrspace(1) | ||
| br i1 %pred0, label %for.body, label %for.body1 | ||
| 
     | 
||
| for.body: | ||
| %0 = atomicrmw fadd ptr addrspace(1) %p.global, double %d monotonic, align 8, !amdgpu.no.fine.grained.memory !0, !amdgpu.no.remote.memory !0 | ||
| br label %if.end | ||
| 
     | 
||
| for.body1: | ||
| br i1 %pred1, label %if.then, label %if.end | ||
| 
     | 
||
| if.then: | ||
| %1 = atomicrmw fadd ptr addrspace(1) %p.global, double %d monotonic, align 8, !amdgpu.no.fine.grained.memory !0, !amdgpu.no.remote.memory !0 | ||
| br label %if.end | ||
| 
     | 
||
| if.end: | ||
| ret void | ||
| } | ||
| 
     | 
||
| !0 = !{!"float", !1, i64 0} | ||
| !1 = !{!"omnipotent char", !2, i64 0} | ||
| !2 = !{!"Simple C++ TBAA"} | ||
                
      
                  AlexVlx marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
  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.
Should avoid looking up these IDs until they are finally needed below.
If we're going to handle these here, we probably ought to promote these to recognized enum metadata
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.
Possibly, but there's no other example of target specific MD in the fixed enum. It's also not quite clear where else we could handle these (if you have something in mind, please share). I will re-factor this a bit anyway because it's incomplete (we're missing cases where the replaces Instr carries the MD).
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.
But it shouldn't really be an issue to add one with the target prefix in the name. It's not really any different than how calling conventions are defined, with a target prefix but it's an IR global constant