Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeGenPrepare] Fold br(freeze(icmp x, const)) to br(icmp(freeze x, …
…const)) Summary: This patch helps CodeGenPrepare move freeze into the icmp when it is used by branch. It reenables generation of efficient conditional jumps. This is only done when at least one of icmp's operands is constant to prevent the transformation from increasing # of freeze instructions. Performance degradation of MultiSource/Benchmarks/Ptrdist/yacr2/yacr2.test is resolved with this patch. Checked with Alive2 Reviewers: reames, fhahn, nlopes Reviewed By: reames Subscribers: jdoerfert, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75859
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt -S -codegenprepare < %s | FileCheck %s | ||
|
||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define void @f1(i32 %a) { | ||
; CHECK-LABEL: @f1( | ||
; CHECK-NEXT: [[FR1:%.*]] = freeze i32 [[A:%.*]] | ||
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[FR1]], 0 | ||
; CHECK-NEXT: br i1 [[C]], label [[A:%.*]], label [[B:%.*]] | ||
; CHECK: A: | ||
; CHECK-NEXT: call void @g1() | ||
; CHECK-NEXT: ret void | ||
; CHECK: B: | ||
; CHECK-NEXT: call void @g2() | ||
; CHECK-NEXT: ret void | ||
; | ||
%c = icmp eq i32 %a, 0 | ||
%fr = freeze i1 %c | ||
br i1 %fr, label %A, label %B | ||
A: | ||
call void @g1() | ||
ret void | ||
B: | ||
call void @g2() | ||
ret void | ||
} | ||
|
||
define void @f2(i32 %a) { | ||
; CHECK-LABEL: @f2( | ||
; CHECK-NEXT: [[FR1:%.*]] = freeze i32 [[A:%.*]] | ||
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 0, [[FR1]] | ||
; CHECK-NEXT: br i1 [[C]], label [[A:%.*]], label [[B:%.*]] | ||
; CHECK: A: | ||
; CHECK-NEXT: call void @g1() | ||
; CHECK-NEXT: ret void | ||
; CHECK: B: | ||
; CHECK-NEXT: call void @g2() | ||
; CHECK-NEXT: ret void | ||
; | ||
%c = icmp eq i32 0, %a | ||
%fr = freeze i1 %c | ||
br i1 %fr, label %A, label %B | ||
A: | ||
call void @g1() | ||
ret void | ||
B: | ||
call void @g2() | ||
ret void | ||
} | ||
|
||
define void @f3(i32 %a) { | ||
; CHECK-LABEL: @f3( | ||
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 0, 1 | ||
; CHECK-NEXT: br i1 [[C]], label [[A:%.*]], label [[B:%.*]] | ||
; CHECK: A: | ||
; CHECK-NEXT: call void @g1() | ||
; CHECK-NEXT: ret void | ||
; CHECK: B: | ||
; CHECK-NEXT: call void @g2() | ||
; CHECK-NEXT: ret void | ||
; | ||
%c = icmp eq i32 0, 1 | ||
%fr = freeze i1 %c | ||
br i1 %fr, label %A, label %B | ||
A: | ||
call void @g1() | ||
ret void | ||
B: | ||
call void @g2() | ||
ret void | ||
} | ||
|
||
declare void @g1() | ||
declare void @g2() |