[PATCH] D86850: [LoopRotate][WIP] Check code-motion safety before hoisting

rithik sharma via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 30 10:25:42 PDT 2020


RithikSharma created this revision.
RithikSharma added reviewers: Whitney, bmahjour, etiotto.
RithikSharma added a project: LLVM.
Herald added subscribers: llvm-commits, danielkiss, hiraditya.
RithikSharma requested review of this revision.

This patch adds checking of code-motion safety before hoisting, Loop rotate considers moving memory instructions as unsafe we used CodeMoverUtils to check code-motion safety of memory instructions and included other pass independent checks, It hoists more memory instructions resulting in less duplication.

LoopRotate:

  define void @test(i32 %n, i32* %A) {
    %cond1 = icmp slt i32 0, %n
    %0 = load i32, i32* %A
    %1 = add nsw i32 %0, 5
    br i1 %cond1, label %body.lr.ph, label %exit
  
  body.lr.ph:                                       ; preds = %entry
    br label %body
  
  body:                                             ; preds = %body.lr.ph, %latch
    %i2 = phi i32 [ 0, %body.lr.ph ], [ %i.next, %latch ]
    br label %latch
  
  latch:                                            ; preds = %body
    %i.next = add nsw i32 %i2, 1
    %cond = icmp slt i32 %i.next, %n
    %2 = load i32, i32* %A
    %3 = add nsw i32 %2, 5
    br i1 %cond, label %body, label %for.header.exit_crit_edge
  
  for.header.exit_crit_edge:                        ; preds = %latch
    br label %exit
  
  exit:                                             ; preds = %for.header.exit_crit_edge, %entry
    ret void
  }

CodeMoverUtils:

  define void @test(i32 %n, i32* %A) {
  entry:
    %cond1 = icmp slt i32 0, %n
    %0 = load i32, i32* %A, align 4
    %1 = add nsw i32 %0, 5
    br i1 %cond1, label %body.lr.ph, label %exit
  
  body.lr.ph:                                       ; preds = %entry
    br label %body
  
  body:                                             ; preds = %body.lr.ph, %latch
    %i2 = phi i32 [ 0, %body.lr.ph ], [ %i.next, %latch ]
    br label %latch
  
  latch:                                            ; preds = %body
    %i.next = add nsw i32 %i2, 1
    %cond = icmp slt i32 %i.next, %n
    br i1 %cond, label %body, label %for.header.exit_crit_edge
  
  for.header.exit_crit_edge:                        ; preds = %latch
    br label %exit
  
  exit:                                             ; preds = %for.header.exit_crit_edge, %entry
    ret void
  }

This shows more hoisting of instructions and less duplication after using code-motion checks before hoisting. 
PS: Some test case are failing. I'm working to fix them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86850

Files:
  llvm/include/llvm/Transforms/Scalar/LoopRotation.h
  llvm/include/llvm/Transforms/Utils/LoopRotationUtils.h
  llvm/lib/Transforms/Scalar/LoopRotation.cpp
  llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
  llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
  llvm/unittests/Transforms/Utils/LoopRotationUtilsTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86850.288859.patch
Type: text/x-patch
Size: 12173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200830/13b596c4/attachment.bin>


More information about the llvm-commits mailing list