[JumpThreading] Thread jumps through two basic blocks
authorKazu Hirata <kazu@google.com>
Wed, 8 Jan 2020 14:57:36 +0000 (06:57 -0800)
committerKazu Hirata <kazu@google.com>
Wed, 8 Jan 2020 14:57:36 +0000 (06:57 -0800)
commitead815924e6ebeaf02c31c37ebf7a560b5fdf67b
treeaff6e36937fef603deb76b190ff6d72c7ef1e88d
parentdac7b23cc3efbb4ccb6a9ea101f367f866f334e2
[JumpThreading] Thread jumps through two basic blocks

Summary:
This patch teaches JumpThreading.cpp to thread through two basic
blocks like:

  bb3:
    %var = phi i32* [ null, %bb1 ], [ @a, %bb2 ]
    %tobool = icmp eq i32 %cond, 0
    br i1 %tobool, label %bb4, label ...

  bb4:
    %cmp = icmp eq i32* %var, null
    br i1 %cmp, label bb5, label bb6

by duplicating basic blocks like bb3 above.  Once we duplicate bb3 as
bb3.dup and redirect edge bb2->bb3 to bb2->bb3.dup, we have:

  bb3:
    %var = phi i32* [ @a, %bb2 ]
    %tobool = icmp eq i32 %cond, 0
    br i1 %tobool, label %bb4, label ...

  bb3.dup:
    %var = phi i32* [ null, %bb1 ]
    %tobool = icmp eq i32 %cond, 0
    br i1 %tobool, label %bb4, label ...

  bb4:
    %cmp = icmp eq i32* %var, null
    br i1 %cmp, label bb5, label bb6

Then the existing code in JumpThreading.cpp can thread edge
bb3.dup->bb4 through bb4 and eventually create bb3.dup->bb5.

Reviewers: wmi

Subscribers: hiraditya, jfb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70247
llvm/include/llvm/Transforms/Scalar/JumpThreading.h
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/thread-two-bbs1.ll [new file with mode: 0644]
llvm/test/Transforms/JumpThreading/thread-two-bbs2.ll [new file with mode: 0644]