[PATCH] D84949: [JumpThreading] Don't limit the type of an operand
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 07:52:44 PDT 2020
aqjune created this revision.
aqjune added reviewers: efriedma, nikic, lebedev.ri.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
aqjune requested review of this revision.
Compared to the optimized code with branch conditions never frozen,
limiting the type of freeze's operand causes generation of suboptimal code in
some cases.
I would like to suggest removing the constraint, as this patch does.
If the number of freeze instructions becomes significant, this can be revisited.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84949
Files:
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/freeze.ll
Index: llvm/test/Transforms/JumpThreading/freeze.ll
===================================================================
--- llvm/test/Transforms/JumpThreading/freeze.ll
+++ llvm/test/Transforms/JumpThreading/freeze.ll
@@ -85,20 +85,14 @@
define i32 @test1_cast2(i1 %cond) {
; CHECK-LABEL: @test1_cast2(
-; CHECK-NEXT: br i1 [[COND:%.*]], label [[MERGE_THREAD:%.*]], label [[MERGE:%.*]]
-; CHECK: Merge.thread:
-; CHECK-NEXT: [[V1:%.*]] = call i32 @f1()
-; CHECK-NEXT: br label [[T2:%.*]]
-; CHECK: Merge:
-; CHECK-NEXT: [[V2:%.*]] = call i32 @f2()
-; CHECK-NEXT: [[A0_FR:%.*]] = freeze i32 0
-; CHECK-NEXT: [[A_FR:%.*]] = trunc i32 [[A0_FR]] to i1
-; CHECK-NEXT: br i1 [[A_FR]], label [[T2]], label [[F2:%.*]]
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[T2:%.*]], label [[F2:%.*]]
; CHECK: T2:
-; CHECK-NEXT: [[B5:%.*]] = phi i32 [ [[V1]], [[MERGE_THREAD]] ], [ [[V2]], [[MERGE]] ]
+; CHECK-NEXT: [[V1:%.*]] = call i32 @f1()
; CHECK-NEXT: call void @f3()
-; CHECK-NEXT: ret i32 [[B5]]
+; CHECK-NEXT: ret i32 [[V1]]
; CHECK: F2:
+; CHECK-NEXT: [[V2:%.*]] = call i32 @f2()
+; CHECK-NEXT: [[A0_FR:%.*]] = freeze i32 0
; CHECK-NEXT: ret i32 [[V2]]
;
br i1 %cond, label %T1, label %F1
Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -700,12 +700,10 @@
return true;
}
- // Handle Freeze instructions, in a manner similar to Cast.
if (FreezeInst *FI = dyn_cast<FreezeInst>(I)) {
Value *Source = FI->getOperand(0);
- if (!isa<PHINode>(Source) && !isa<CmpInst>(Source) &&
- !isa<CastInst>(Source))
- return false;
+ // Unlike cast, don't limit the type of Source because it generates a
+ // sub-optimal code compared to the case when branch conditions are unfrozen
ComputeValueKnownInPredecessorsImpl(Source, BB, Result, Preference,
RecursionSet, CxtI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84949.281931.patch
Type: text/x-patch
Size: 2089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200730/209846b5/attachment.bin>
More information about the llvm-commits
mailing list