- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15k
[InstCombine] Fold reconstruction across select #145102
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
          
     Open
      
      
            macsencasaus
  wants to merge
  6
  commits into
  llvm:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
macsencasaus:144020
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +162
        
        
          −0
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      683da5c
              
                pre-commit test
              
              
                macsencasaus 6f0a946
              
                [InstCombine] Fold reconstruction across select
              
              
                macsencasaus 9542631
              
                address review comments
              
              
                macsencasaus f5bcc06
              
                match correct mask only
              
              
                macsencasaus 039432c
              
                match constant V2 value only
              
              
                 1ec984a
              
                match V1 as constant
              
              
                 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
    
  
  
    
              
        
          
          
            120 changes: 120 additions & 0 deletions
          
          120 
        
  llvm/test/Transforms/InstCombine/select-reconstruction.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,120 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|  | ||
| define i40 @select_reconstruction_i40(i40 %arg0) { | ||
| ; CHECK-LABEL: define i40 @select_reconstruction_i40( | ||
| ; CHECK-SAME: i40 [[ARG0:%.*]]) { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = trunc i40 [[ARG0]] to i8 | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], 2 | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i40 0, i40 [[ARG0]] | ||
| ; CHECK-NEXT: ret i40 [[TMP3]] | ||
| ; | ||
| %low = trunc i40 %arg0 to i8 | ||
| %is_low_two = icmp eq i8 %low, 2 | ||
| %high = and i40 %arg0, -256 | ||
| %select_low = select i1 %is_low_two, i8 0, i8 %low | ||
| %select_high = select i1 %is_low_two, i40 0, i40 %high | ||
| %zext_low = zext i8 %select_low to i40 | ||
| %recomb = or disjoint i40 %select_high, %zext_low | ||
| ret i40 %recomb | ||
| } | ||
|  | ||
| define i40 @select_reconstruction_any_cmp_val(i40 %arg0, i8 %arg1) { | ||
| ; CHECK-LABEL: define i40 @select_reconstruction_any_cmp_val( | ||
| ; CHECK-SAME: i40 [[ARG0:%.*]], i8 [[ARG1:%.*]]) { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = trunc i40 [[ARG0]] to i8 | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[ARG1]], [[TMP1]] | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i40 0, i40 [[ARG0]] | ||
| ; CHECK-NEXT: ret i40 [[TMP3]] | ||
| ; | ||
| %low = trunc i40 %arg0 to i8 | ||
| %is_low_arg1 = icmp eq i8 %low, %arg1 | ||
| %high = and i40 %arg0, -256 | ||
| %select_low = select i1 %is_low_arg1, i8 0, i8 %low | ||
| %select_high = select i1 %is_low_arg1, i40 0, i40 %high | ||
| %zext_low = zext i8 %select_low to i40 | ||
| %recomb = or disjoint i40 %select_high, %zext_low | ||
| ret i40 %recomb | ||
| } | ||
|  | ||
| ; negative test | ||
| define i40 @select_reconstruction_257_mask(i40 %arg0) { | ||
| ; CHECK-LABEL: define i40 @select_reconstruction_257_mask( | ||
| ; CHECK-SAME: i40 [[ARG0:%.*]]) { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = trunc i40 [[ARG0]] to i8 | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], 2 | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = and i40 [[ARG0]], -257 | ||
| ; CHECK-NEXT: [[SELECT_LOW:%.*]] = select i1 [[TMP2]], i8 0, i8 [[TMP1]] | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], i40 0, i40 [[TMP3]] | ||
| ; CHECK-NEXT: [[ZEXT_LOW:%.*]] = zext i8 [[SELECT_LOW]] to i40 | ||
| ; CHECK-NEXT: [[RECOMB:%.*]] = or disjoint i40 [[TMP4]], [[ZEXT_LOW]] | ||
| ; CHECK-NEXT: ret i40 [[RECOMB]] | ||
| ; | ||
| %low = trunc i40 %arg0 to i8 | ||
| %is_low_two = icmp eq i8 %low, 2 | ||
| %high = and i40 %arg0, -257 | ||
| %select_low = select i1 %is_low_two, i8 0, i8 %low | ||
| %select_high = select i1 %is_low_two, i40 0, i40 %high | ||
| %zext_low = zext i8 %select_low to i40 | ||
| %recomb = or disjoint i40 %select_high, %zext_low | ||
| ret i40 %recomb | ||
| } | ||
|  | ||
| define i40 @select_reconstruction_i16_mask(i40 %arg0) { | ||
| ; CHECK-LABEL: define i40 @select_reconstruction_i16_mask( | ||
| ; CHECK-SAME: i40 [[ARG0:%.*]]) { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = trunc i40 [[ARG0]] to i16 | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i16 [[TMP1]], 2 | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i40 0, i40 [[ARG0]] | ||
| ; CHECK-NEXT: ret i40 [[TMP3]] | ||
| ; | ||
| %low = trunc i40 %arg0 to i16 | ||
| %is_low_two = icmp eq i16 %low, 2 | ||
| %high = and i40 %arg0, -65536 | ||
| %select_low = select i1 %is_low_two, i16 0, i16 %low | ||
| %select_high = select i1 %is_low_two, i40 0, i40 %high | ||
| %zext_low = zext i16 %select_low to i40 | ||
| %recomb = or disjoint i40 %select_high, %zext_low | ||
| ret i40 %recomb | ||
| } | ||
|  | ||
| define <2 x i32> @select_reconstruction_vec_any_cmp_val(<2 x i32> %arg0, <2 x i8> %arg1) { | ||
| ; CHECK-LABEL: define <2 x i32> @select_reconstruction_vec_any_cmp_val( | ||
| ; CHECK-SAME: <2 x i32> [[ARG0:%.*]], <2 x i8> [[ARG1:%.*]]) { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i32> [[ARG0]] to <2 x i8> | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i8> [[ARG1]], [[TMP1]] | ||
| ; CHECK-NEXT: [[TMP7:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> zeroinitializer, <2 x i32> [[ARG0]] | ||
| ; CHECK-NEXT: ret <2 x i32> [[TMP7]] | ||
| ; | ||
| %low = trunc <2 x i32> %arg0 to <2 x i8> | ||
| %is_low_arg1 = icmp eq <2 x i8> %low, %arg1 | ||
| %high = and <2 x i32> %arg0, <i32 -256, i32 -256> | ||
| %select_low = select <2 x i1> %is_low_arg1, <2 x i8> <i8 0, i8 0>, <2 x i8> %low | ||
| %select_high = select <2 x i1> %is_low_arg1, <2 x i32> <i32 0, i32 0>, <2 x i32> %high | ||
| %zext_low = zext <2 x i8> %select_low to <2 x i32> | ||
| %recomb = or <2 x i32> %select_high, %zext_low | ||
| ret <2 x i32> %recomb | ||
| } | ||
|  | ||
| ; negative test | ||
| define i40 @select_reconstruction_impure_i16_mask_and(i40 %arg0) { | ||
| ; CHECK-LABEL: define i40 @select_reconstruction_impure_i16_mask_and( | ||
| ; CHECK-SAME: i40 [[ARG0:%.*]]) { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = trunc i40 [[ARG0]] to i16 | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i16 [[TMP1]], 2 | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = and i40 [[ARG0]], 180 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], i16 0, i16 [[TMP1]] | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], i40 0, i40 [[TMP3]] | ||
| ; CHECK-NEXT: [[TMP6:%.*]] = zext i16 [[TMP4]] to i40 | ||
| ; CHECK-NEXT: [[TMP7:%.*]] = and i40 [[TMP5]], [[TMP6]] | ||
| ; CHECK-NEXT: ret i40 [[TMP7]] | ||
| ; | ||
| %low = trunc i40 %arg0 to i16 | ||
| %is_low_two = icmp eq i16 %low, 2 | ||
| %high = and i40 %arg0, -65356 | ||
| %select_low = select i1 %is_low_two, i16 0, i16 %low | ||
| %select_high = select i1 %is_low_two, i40 0, i40 %high | ||
| %zext_low = zext i16 %select_low to i40 | ||
| %recomb = and i40 %select_high, %zext_low | ||
| ret i40 %recomb | ||
| } | 
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.