[llvm] e0d99e9 - [JumpThreading] Consider freeze as a zero-cost instruction
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 4 22:43:10 PDT 2020
Author: Juneyoung Lee
Date: 2020-08-05T14:42:36+09:00
New Revision: e0d99e9aaf51dac0555655cbf17909377ed37a27
URL: https://github.com/llvm/llvm-project/commit/e0d99e9aaf51dac0555655cbf17909377ed37a27
DIFF: https://github.com/llvm/llvm-project/commit/e0d99e9aaf51dac0555655cbf17909377ed37a27.diff
LOG: [JumpThreading] Consider freeze as a zero-cost instruction
This is a simple patch that makes freeze as a zero-cost instruction, as bitcast already is.
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D85023
Added:
Modified:
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/thread-two-bbs-threshold.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index e6d261fa9aff..57ebeeaa7e17 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -535,6 +535,10 @@ static unsigned getJumpThreadDuplicationCost(BasicBlock *BB,
if (isa<BitCastInst>(I) && I->getType()->isPointerTy())
continue;
+ // Freeze instruction is free, too.
+ if (isa<FreezeInst>(I))
+ continue;
+
// Bail out if this instruction gives back a token type, it is not possible
// to duplicate it if it is used outside this BB.
if (I->getType()->isTokenTy() && I->isUsedOutsideOfBlock(BB))
diff --git a/llvm/test/Transforms/JumpThreading/thread-two-bbs-threshold.ll b/llvm/test/Transforms/JumpThreading/thread-two-bbs-threshold.ll
index 5650d8b5a83b..9b8273db1883 100644
--- a/llvm/test/Transforms/JumpThreading/thread-two-bbs-threshold.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-two-bbs-threshold.ll
@@ -6,30 +6,31 @@ target triple = "x86_64-unknown-linux-gnu"
@a = global i32 0, align 4
+; Show that freeze is not counted when comparing the cost with the threshold
define void @foo(i32 %cond1, i32 %cond2) {
; CHECK-LABEL: @foo(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[COND1:%.*]], 0
-; CHECK-NEXT: br i1 [[TOBOOL]], label [[BB_COND2:%.*]], label [[BB_F1:%.*]]
-; CHECK: bb.f1:
-; CHECK-NEXT: call void @f1()
-; CHECK-NEXT: br label [[BB_COND2]]
+; CHECK-NEXT: br i1 [[TOBOOL]], label [[BB_COND2_THREAD:%.*]], label [[BB_COND2:%.*]]
; CHECK: bb.cond2:
-; CHECK-NEXT: [[PTR:%.*]] = phi i32* [ null, [[BB_F1]] ], [ @a, [[ENTRY:%.*]] ]
+; CHECK-NEXT: call void @f1()
; CHECK-NEXT: [[COND2_FR:%.*]] = freeze i32 [[COND2:%.*]]
; CHECK-NEXT: [[X:%.*]] = add i32 [[COND2_FR]], 1
; CHECK-NEXT: [[TOBOOL1:%.*]] = icmp eq i32 [[X]], 0
-; CHECK-NEXT: br i1 [[TOBOOL1]], label [[BB_FILE:%.*]], label [[BB_F2:%.*]]
+; CHECK-NEXT: br i1 [[TOBOOL1]], label [[BB_F4:%.*]], label [[BB_F2:%.*]]
+; CHECK: bb.cond2.thread:
+; CHECK-NEXT: [[COND2_FR2:%.*]] = freeze i32 [[COND2]]
+; CHECK-NEXT: [[X3:%.*]] = add i32 [[COND2_FR2]], 1
+; CHECK-NEXT: [[TOBOOL14:%.*]] = icmp eq i32 [[X3]], 0
+; CHECK-NEXT: br i1 [[TOBOOL14]], label [[BB_F3:%.*]], label [[BB_F2]]
; CHECK: bb.f2:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[EXIT:%.*]]
-; CHECK: bb.file:
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[PTR]], null
-; CHECK-NEXT: br i1 [[CMP]], label [[BB_F4:%.*]], label [[BB_F3:%.*]]
; CHECK: bb.f3:
; CHECK-NEXT: call void @f3()
; CHECK-NEXT: br label [[EXIT]]
; CHECK: bb.f4:
+; CHECK-NEXT: [[PTR5:%.*]] = phi i32* [ null, [[BB_COND2]] ]
; CHECK-NEXT: call void @f4()
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
More information about the llvm-commits
mailing list