[PATCH] D106317: [SimplifyCFG] performBranchToCommonDestFolding(): form sudo-LCSSA before cloning instructions (PR51125)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 19 14:54:28 PDT 2021


lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, jdoerfert, nikic.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri requested review of this revision.

LLVM IR SSA form is "implicit" in `@pr51125`. While is a valid LLVM IR,
and does not require any PHI nodes, that completely breaks the further logic
in `CloneInstructionsIntoPredecessorBlockAndUpdateSSAUses()`
that updates the live-out uses of the bonus instructions.

What i believe we need to do, is to first make the SSA form explicit,
by inserting tautological PHI nodes, and rewriting the offending uses.

  $ /builddirs/llvm-project/build-Clang12/bin/opt -load /repositories/alive2/build-Clang-release/tv/tv.so -load-pass-plugin /repositories/alive2/build-Clang-release/tv/tv.so -tv -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -bonus-inst-threshold=10 -tv -o /dev/null /tmp/test.ll 
  
  ----------------------------------------
  @global_pr51125 = global 4 bytes, align 4
  
  define i32 @pr51125() {
  %entry:
    br label %L
  
  %L:
    %ld = load i32, * @global_pr51125, align 4
    %iszero = icmp eq i32 %ld, 0
    br i1 %iszero, label %exit, label %L2
  
  %L2:
    store i32 4294967295, * @global_pr51125, align 4
    %cmp = icmp eq i32 %ld, 4294967295
    br i1 %cmp, label %L, label %exit
  
  %exit:
    %r = phi i32 [ %ld, %L2 ], [ %ld, %L ]
    ret i32 %r
  }
  =>
  @global_pr51125 = global 4 bytes, align 4
  
  define i32 @pr51125() {
  %entry:
    %ld.old = load i32, * @global_pr51125, align 4
    %iszero.old = icmp eq i32 %ld.old, 0
    br i1 %iszero.old, label %exit, label %L2
  
  %L2:
    %ld2 = phi i32 [ %ld.old, %entry ], [ %ld, %L2 ]
    store i32 4294967295, * @global_pr51125, align 4
    %cmp = icmp ne i32 %ld2, 4294967295
    %ld = load i32, * @global_pr51125, align 4
    %iszero = icmp eq i32 %ld, 0
    %or.cond = select i1 %cmp, i1 1, i1 %iszero
    br i1 %or.cond, label %exit, label %L2
  
  %exit:
    %ld1 = phi i32 [ poison, %L2 ], [ %ld.old, %entry ]
    %r = phi i32 [ %ld2, %L2 ], [ %ld.old, %entry ]
    ret i32 %r
  }
  Transformation seems to be correct!

Fixes https://bugs.llvm.org/show_bug.cgi?id=51125


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106317

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/fold-branch-to-common-dest.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106317.359928.patch
Type: text/x-patch
Size: 7843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210719/7cb831c2/attachment.bin>


More information about the llvm-commits mailing list