- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
[LV] Align legacy cost model to vplan-based model for gather/scatter w/ uniform addr. #155739
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
Changes from 1 commit
b34a073
              c9eaaa8
              3a0ff8d
              9c165a4
              87a22c8
              222ff40
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,190 @@ | ||||||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||||||
| ; RUN: opt < %s -passes=loop-vectorize -mtriple riscv64 -mattr=+rva23u64 -S | FileCheck %s -check-prefixes=CHECK,RVA23 | ||||||
| ; RUN: opt < %s -passes=loop-vectorize -mtriple riscv64 -mattr=+rva23u64,+zvl1024b -S | FileCheck %s -check-prefixes=CHECK,RVA23ZVL1024B | ||||||
| 
     | 
||||||
| define i32 @getNeighborBoxes(ptr %boxes, i32 %iBox, ptr %nbrBoxes) { | ||||||
| ; CHECK-LABEL: @getNeighborBoxes( | ||||||
| ; CHECK-NEXT: entry: | ||||||
| ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[IBOX:%.*]] to i64 | ||||||
| ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[TMP0]], 1 | ||||||
| ; CHECK-NEXT: [[SMAX2:%.*]] = call i64 @llvm.smax.i64(i64 [[TMP1]], i64 0) | ||||||
| ; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[SMAX2]] to i32 | ||||||
| ; CHECK-NEXT: [[TMP3:%.*]] = add nuw i32 [[TMP2]], 1 | ||||||
| ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]] | ||||||
| ; CHECK: vector.scevcheck: | ||||||
| ; CHECK-NEXT: [[TMP4:%.*]] = sext i32 [[IBOX]] to i64 | ||||||
| ; CHECK-NEXT: [[TMP5:%.*]] = add nsw i64 [[TMP4]], 1 | ||||||
| ; CHECK-NEXT: [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[TMP5]], i64 0) | ||||||
| ; CHECK-NEXT: [[TMP6:%.*]] = trunc i64 [[SMAX]] to i32 | ||||||
| ; CHECK-NEXT: [[TMP7:%.*]] = icmp slt i32 [[TMP6]], 0 | ||||||
| ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[SMAX]], 4294967295 | ||||||
| ; CHECK-NEXT: [[TMP9:%.*]] = or i1 [[TMP7]], [[TMP8]] | ||||||
| ; CHECK-NEXT: br i1 [[TMP9]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK:%.*]] | ||||||
| ; CHECK: vector.memcheck: | ||||||
| ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[NBRBOXES:%.*]], i64 4 | ||||||
| ; CHECK-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[BOXES:%.*]], i64 4 | ||||||
| ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[NBRBOXES]], [[SCEVGEP1]] | ||||||
| ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[BOXES]], [[SCEVGEP]] | ||||||
| ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]] | ||||||
| ; CHECK-NEXT: br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]] | ||||||
| ; CHECK: vector.ph: | ||||||
| ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x ptr> poison, ptr [[BOXES]], i64 0 | ||||||
| ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 4 x ptr> poison, <vscale x 4 x i32> zeroinitializer | ||||||
| ; CHECK-NEXT: [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <vscale x 4 x ptr> poison, ptr [[NBRBOXES]], i64 0 | ||||||
| ; CHECK-NEXT: [[BROADCAST_SPLAT4:%.*]] = shufflevector <vscale x 4 x ptr> [[BROADCAST_SPLATINSERT3]], <vscale x 4 x ptr> poison, <vscale x 4 x i32> zeroinitializer | ||||||
| ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] | ||||||
| ; CHECK: vector.body: | ||||||
| ; CHECK-NEXT: [[AVL:%.*]] = phi i32 [ [[TMP3]], [[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], [[VECTOR_BODY]] ] | ||||||
| ; CHECK-NEXT: [[TMP10:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[AVL]], i32 4, i1 true) | ||||||
| ; CHECK-NEXT: [[BROADCAST_SPLATINSERT5:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[TMP10]], i64 0 | ||||||
| ; CHECK-NEXT: [[BROADCAST_SPLAT6:%.*]] = shufflevector <vscale x 4 x i32> [[BROADCAST_SPLATINSERT5]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer | ||||||
| ; CHECK-NEXT: [[TMP11:%.*]] = call <vscale x 4 x i32> @llvm.stepvector.nxv4i32() | ||||||
| ; CHECK-NEXT: [[TMP12:%.*]] = icmp ult <vscale x 4 x i32> [[TMP11]], [[BROADCAST_SPLAT6]] | ||||||
| ; CHECK-NEXT: [[TMP13:%.*]] = select <vscale x 4 x i1> [[TMP12]], <vscale x 4 x i1> splat (i1 true), <vscale x 4 x i1> zeroinitializer | ||||||
| ; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.vp.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> align 4 [[BROADCAST_SPLAT]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP10]]), !alias.scope [[META0:![0-9]+]] | ||||||
| ; CHECK-NEXT: [[TMP14:%.*]] = select <vscale x 4 x i1> [[TMP12]], <vscale x 4 x i1> zeroinitializer, <vscale x 4 x i1> zeroinitializer | ||||||
| ; CHECK-NEXT: [[TMP15:%.*]] = or <vscale x 4 x i1> [[TMP13]], [[TMP14]] | ||||||
| ; CHECK-NEXT: [[PREDPHI:%.*]] = select <vscale x 4 x i1> [[TMP14]], <vscale x 4 x i32> zeroinitializer, <vscale x 4 x i32> [[WIDE_MASKED_GATHER]] | ||||||
| ; CHECK-NEXT: call void @llvm.vp.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[PREDPHI]], <vscale x 4 x ptr> align 4 [[BROADCAST_SPLAT4]], <vscale x 4 x i1> [[TMP15]], i32 [[TMP10]]), !alias.scope [[META3:![0-9]+]], !noalias [[META0]] | ||||||
| ; CHECK-NEXT: [[AVL_NEXT]] = sub nuw i32 [[AVL]], [[TMP10]] | ||||||
| ; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i32 [[AVL_NEXT]], 0 | ||||||
| ; CHECK-NEXT: br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]] | ||||||
| ; CHECK: middle.block: | ||||||
| ; CHECK-NEXT: br label [[EXIT:%.*]] | ||||||
| ; CHECK: scalar.ph: | ||||||
| ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[VECTOR_MEMCHECK]] ] | ||||||
| ; CHECK-NEXT: br label [[LOOP:%.*]] | ||||||
| ; CHECK: loop: | ||||||
| ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP_EXIT:%.*]] ] | ||||||
| ; CHECK-NEXT: br i1 false, label [[EXIT_CRIT_EDGE:%.*]], label [[IF:%.*]] | ||||||
| ; CHECK: exit_crit_edge: | ||||||
| ; CHECK-NEXT: br label [[LOOP_EXIT]] | ||||||
| ; CHECK: if: | ||||||
| ; CHECK-NEXT: [[TMP17:%.*]] = load i32, ptr [[BOXES]], align 4 | ||||||
| ; CHECK-NEXT: br label [[LOOP_EXIT]] | ||||||
| ; CHECK: loop.exit: | ||||||
| ; CHECK-NEXT: [[IBOX_0_I:%.*]] = phi i32 [ [[TMP17]], [[IF]] ], [ 0, [[EXIT_CRIT_EDGE]] ] | ||||||
| ; CHECK-NEXT: store i32 [[IBOX_0_I]], ptr [[NBRBOXES]], align 4 | ||||||
| ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1 | ||||||
| ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp sgt i32 [[IV]], [[IBOX]] | ||||||
| ; CHECK-NEXT: br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP9:![0-9]+]] | ||||||
| ; CHECK: exit: | ||||||
| ; CHECK-NEXT: ret i32 0 | ||||||
| ; | ||||||
| entry: | ||||||
| br label %loop | ||||||
| 
     | 
||||||
| loop: | ||||||
| %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.exit ] | ||||||
| br i1 false, label %exit_crit_edge, label %if | ||||||
                
       | 
||||||
| 
     | 
||||||
| exit_crit_edge: | ||||||
                
       | 
||||||
| exit_crit_edge: | |
| loop.then: | 
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.
Updated, thanks!
        
          
              
                Outdated
          
        
      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.
loop.else:
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.
Updated, thanks
        
          
              
                Outdated
          
        
      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.
| %0 = load i32, ptr %boxes, align 4 | |
| %0 = load i32, ptr %src, align 4 | 
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.
Updated, thanks!
        
          
              
                Outdated
          
        
      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.
| loop.exit: | |
| loop.latch: | 
this is not the exit of the loop, but the (exiting) latch in LLVM terminology.
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.
Fixed, thanks!
        
          
              
                Outdated
          
        
      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.
| %exitcond = icmp sgt i32 %iv, %iBox | |
| %exitcond = icmp sgt i32 %iv, %n | 
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.
Done.
        
          
              
                  Mel-Chen marked this conversation as resolved.
              
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
              
                Outdated
          
        
      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.
Could you adjust the names to be more descriptive, instead of using the ones from the original source function? Also above
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.
Updated, thanks!
        
          
              
                Outdated
          
        
      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.
please avoid null, it makes the function have immediate UB on the store
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 non-null value, thanks!
Uh oh!
There was an error while loading. Please reload this page.