[PATCH] D107180: [InstCombine] Prevent unnecessary sinks caused by the Freeze
    Hyeongyu Kim via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri Jul 30 10:00:56 PDT 2021
    
    
  
hyeongyukim created this revision.
Herald added a subscriber: hiraditya.
hyeongyukim requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The Freeze is added to Cond in fixing the miscomputation of loop unswitch(D106041 <https://reviews.llvm.org/D106041>).
However, more sinks are generated in Instcombine by Freeze that added in D106041 <https://reviews.llvm.org/D106041>.
Below is a situation where D106041 <https://reviews.llvm.org/D106041> is not applied(bug exists in LU).
If D106041 <https://reviews.llvm.org/D106041> is not applied, `load(ptr)` will not sink after InstCombine is performed.
    v = load(ptr)
    cond = icmp eq(v, 0)
    br body
  
  body:
    br(cond, ..., ...)
  =>
    v = load(ptr)
    br body
  
  body:
    cond = icmp eq(v, 0)
    br(cond, ..., ...)
But when we add the Freeze to `Cond`(to fix LU), `load(ptr)` is sink to body block.
And this is not the intended situation.
    v = load(ptr)
    cond = icmp eq(v, 0)
    cond.fr = freeze(cond)
    br body
  
  body:
    br(cond.fr, ..., ...)
  =>
    br body
  
  body:
    v = load(ptr)
    v.fr = freeze(v)
    cond = icmp eq(v, 0)
    br(cond, ..., ...)
Once this patch is applied, the load will not sink, but only Freeze and icmp will sink as below.
    v = load(ptr)
    cond = icmp eq(v, 0)
    cond.fr = freeze(cond)
    br body
  
  body:
    br(cond.fr, ..., ...)
  =>
    v = load(ptr)
    br body
  
  body:
    v.fr = freeze(v)
    cond = icmp eq(v, 0)
    br(cond, ..., ...)
Repository:
  rG LLVM Github Monorepo
https://reviews.llvm.org/D107180
Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/sink_instruction.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107180.363130.patch
Type: text/x-patch
Size: 4288 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210730/f8342e54/attachment.bin>
    
    
More information about the llvm-commits
mailing list