- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
[DAGCombiner] Teach SearchForAndLoads to handle an AND with 2 constant operands. #142062
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 all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      2506cff
              
                Pre-commit test
              
              
                topperc 9c11eed
              
                [DAGCombiner] Teach SearchForAndLoads to handle an AND with 2 constan…
              
              
                topperc f1d92ee
              
                fixup! Use assert
              
              
                topperc 0143a2a
              
                Merge remote-tracking branch 'origin/main' into pr/142004
              
              
                topperc d5ea666
              
                Merge remote-tracking branch 'origin/main' into pr/142004
              
              
                topperc 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
    
  
  
    
              
  
    
      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,33 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc < %s -mtriple=riscv64 | FileCheck %s | ||
| 
     | 
||
| @f = global i64 0, align 8 | ||
| @d = global i64 0, align 8 | ||
| @e = global i32 0, align 8 | ||
| 
     | 
||
| define i32 @foo(i32 %x) { | ||
| ; CHECK-LABEL: foo: | ||
| ; CHECK: # %bb.0: # %entry | ||
| ; CHECK-NEXT: lui a1, %hi(f) | ||
| ; CHECK-NEXT: lui a2, %hi(d) | ||
| ; CHECK-NEXT: lbu a1, %lo(f)(a1) | ||
| ; CHECK-NEXT: lhu a2, %lo(d)(a2) | ||
| ; CHECK-NEXT: slli a0, a0, 48 | ||
| ; CHECK-NEXT: srli a3, a0, 48 | ||
| ; CHECK-NEXT: xori a0, a1, 255 | ||
| ; CHECK-NEXT: or a0, a0, a2 | ||
| ; CHECK-NEXT: lui a1, %hi(e) | ||
| ; CHECK-NEXT: sw a3, %lo(e)(a1) | ||
| ; CHECK-NEXT: ret | ||
| entry: | ||
| %1 = load i64, ptr @f, align 8 | ||
| %conv1 = and i64 %1, 255 | ||
| %conv2 = xor i64 %conv1, 255 | ||
| %2 = load i64, ptr @d, align 8 | ||
| %or = or i64 %conv2, %2 | ||
| %conv3 = trunc i64 %or to i32 | ||
| %conv4 = and i32 %conv3, 65535 | ||
| %and = and i32 %x, 65535 | ||
| store i32 %and, ptr @e | ||
| ret i32 %conv4 | ||
| } | 
  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.
ISD::isBitwiseLogicOp(N->getOpcode())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.
N is always a bitwise op. We can insert an assertion instead.
https://github.com/llvm/llvm-project/blob/2a3afa2feb90844ad0f8b0bc57663e2aec06cd0a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L6858-L6864
https://github.com/llvm/llvm-project/blob/2a3afa2feb90844ad0f8b0bc57663e2aec06cd0a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L6891-L6906
https://github.com/llvm/llvm-project/blob/2a3afa2feb90844ad0f8b0bc57663e2aec06cd0a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L7494-L7501