forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InstCombine] Preserve fast math flags when combining PHIs
Summary: When optimizing PHIs which have inputs floating point binary operators, we preserve all IR flags except the fast math flags. This change removes the logic which tracked some of the IR flags (no wrap, exact) and replaces it by doing an and on the IR flags of all inputs to the PHI - which will also handle the fast math flags. Reviewers: majnemer Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D19370 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267139 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
1 parent
fed867f
commit 883a09c
Showing
2 changed files
with
100 additions
and
38 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,89 @@ | ||
; RUN: opt < %s -instcombine -S -o - | FileCheck %s | ||
|
||
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" | ||
|
||
; CHECK-LABEL: define float @func1( | ||
define float @func1(float %a, float %b, float %c, i1 %cond) { | ||
entry: | ||
br i1 %cond, label %cond.true, label %cond.false | ||
|
||
cond.true: | ||
%sub0 = fsub fast float %a, %b | ||
br label %cond.end | ||
|
||
cond.false: | ||
%sub1 = fsub fast float %a, %c | ||
br label %cond.end | ||
|
||
; The fast-math flags should always be transfered if possible. | ||
; CHECK-LABEL: cond.end | ||
; CHECK [[PHI:%[^ ]*]] = phi float [ %b, %cond.true ], [ %c, %cond.false ] | ||
; CHECK fsub fast float %a, [[PHI]] | ||
cond.end: | ||
%e = phi float [ %sub0, %cond.true ], [ %sub1, %cond.false ] | ||
ret float %e | ||
} | ||
|
||
; CHECK-LABEL: define float @func2( | ||
define float @func2(float %a, float %b, float %c, i1 %cond) { | ||
entry: | ||
br i1 %cond, label %cond.true, label %cond.false | ||
|
||
cond.true: | ||
%sub0 = fsub fast float %a, %b | ||
br label %cond.end | ||
|
||
cond.false: | ||
%sub1 = fsub float %a, %c | ||
br label %cond.end | ||
|
||
; The fast-math flags should always be transfered if possible. | ||
; CHECK-LABEL: cond.end | ||
; CHECK [[PHI:%[^ ]*]] = phi float [ %b, %cond.true ], [ %c, %cond.false ] | ||
; CHECK fsub float %a, [[PHI]] | ||
cond.end: | ||
%e = phi float [ %sub0, %cond.true ], [ %sub1, %cond.false ] | ||
ret float %e | ||
} | ||
|
||
; CHECK-LABEL: define float @func3( | ||
define float @func3(float %a, float %b, float %c, i1 %cond) { | ||
entry: | ||
br i1 %cond, label %cond.true, label %cond.false | ||
|
||
cond.true: | ||
%sub0 = fsub fast float %a, 2.0 | ||
br label %cond.end | ||
|
||
cond.false: | ||
%sub1 = fsub fast float %b, 2.0 | ||
br label %cond.end | ||
|
||
; CHECK-LABEL: cond.end | ||
; CHECK [[PHI:%[^ ]*]] = phi float [ %a, %cond.true ], [ %b, %cond.false ] | ||
; CHECK fadd fast float %a, [[PHI]] | ||
cond.end: | ||
%e = phi float [ %sub0, %cond.true ], [ %sub1, %cond.false ] | ||
ret float %e | ||
} | ||
|
||
; CHECK-LABEL: define float @func4( | ||
define float @func4(float %a, float %b, float %c, i1 %cond) { | ||
entry: | ||
br i1 %cond, label %cond.true, label %cond.false | ||
|
||
cond.true: | ||
%sub0 = fsub fast float %a, 2.0 | ||
br label %cond.end | ||
|
||
cond.false: | ||
%sub1 = fsub float %b, 2.0 | ||
br label %cond.end | ||
|
||
; CHECK-LABEL: cond.end | ||
; CHECK [[PHI:%[^ ]*]] = phi float [ %a, %cond.true ], [ %b, %cond.false ] | ||
; CHECK fadd float %a, [[PHI]] | ||
cond.end: | ||
%e = phi float [ %sub0, %cond.true ], [ %sub1, %cond.false ] | ||
ret float %e | ||
} |