mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
d766c964c9
This reverts commit 41784bed01543315a1d03141e6ddc023fd914c0b. Since the original revision ead815924e6ebeaf02c31c37ebf7a560b5fdf67b, this revision fixes three issues: - This revision fixes the Windows build. My original patch improperly copied EH pads on Windows. This patch disregards jump threading opportunities having to do with EH pads. - This revision fixes jump threading to a wrong destination. Specifically, my original patch treated any Constant other than 0 as 1 while evaluating the branch condition. This bug led to treating constant expressions like: icmp ugt i8* null, inttoptr (i64 4 to i8*) to "true". This patch fixes the bug by calling isOneValue. - This revision fixes the cost calculation of two basic blocks being threaded through. Note that getJumpThreadDuplicationCost returns "(unsigned)~0" for those basic blocks that cannot be duplicated. If we sum of two return values from getJumpThreadDuplicationCost, we could have an unsigned overflow like: (unsigned)~0 + 5 = 4 and mistakenly determine that it's safe and profitable to proceed with the jump threading opportunity. The patch fixes the bug by checking each return value before summing them up. [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
60 lines
1.2 KiB
LLVM
60 lines
1.2 KiB
LLVM
; RUN: opt < %s -jump-threading -S -verify | FileCheck %s
|
|
|
|
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
@a = global i32 0, align 4
|
|
|
|
define void @foo(i32 %cond1, i32 %cond2) {
|
|
; CHECK-LABEL: @foo
|
|
; CHECK-LABEL: entry
|
|
entry:
|
|
%tobool = icmp eq i32 %cond1, 0
|
|
br i1 %tobool, label %bb.cond2, label %bb.f1
|
|
|
|
bb.f1:
|
|
call void @f1()
|
|
br label %bb.cond2
|
|
; Verify that we branch on cond2 without checking ptr.
|
|
; CHECK: call void @f1()
|
|
; CHECK-NEXT: icmp eq i32 %cond2, 0
|
|
; CHECK-NEXT: label %bb.f4, label %bb.f2
|
|
|
|
bb.cond2:
|
|
%ptr = phi i32* [ null, %bb.f1 ], [ @a, %entry ]
|
|
%tobool1 = icmp eq i32 %cond2, 0
|
|
br i1 %tobool1, label %bb.file, label %bb.f2
|
|
; Verify that we branch on cond2 without checking ptr.
|
|
; CHECK: icmp eq i32 %cond2, 0
|
|
; CHECK-NEXT: label %bb.f3, label %bb.f2
|
|
|
|
bb.f2:
|
|
call void @f2()
|
|
br label %exit
|
|
|
|
; Verify that we eliminate this basic block.
|
|
; CHECK-NOT: bb.file:
|
|
bb.file:
|
|
%cmp = icmp eq i32* %ptr, null
|
|
br i1 %cmp, label %bb.f4, label %bb.f3
|
|
|
|
bb.f3:
|
|
call void @f3()
|
|
br label %exit
|
|
|
|
bb.f4:
|
|
call void @f4()
|
|
br label %exit
|
|
|
|
exit:
|
|
ret void
|
|
}
|
|
|
|
declare void @f1()
|
|
|
|
declare void @f2()
|
|
|
|
declare void @f3()
|
|
|
|
declare void @f4()
|