Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InstCombine] Add select simplifications
In these cases, two selects have constant selectable operands for both the true and false components and have the same conditional expression. We then create two arithmetic operations of the same type and feed a final select operation using the result of the true arithmetic for the true operand and the result of the false arithmetic for the false operand and reuse the original conditionl expression. The arithmetic operations are naturally folded as a consequence, leaving only the newly formed select to replace the old arithmetic operation. Patch by: Michael Berg <michael_c_berg@apple.com> Differential Revision: https://reviews.llvm.org/D37019 llvm-svn: 313774
- Loading branch information
Quentin Colombet
committed
Sep 20, 2017
1 parent
d0320d5
commit aa103b3
Showing
5 changed files
with
84 additions
and
52 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
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
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,40 @@ | ||
; RUN: opt < %s -instcombine -S | FileCheck %s | ||
|
||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" | ||
|
||
; Tests folding constants from two similar selects that feed a add | ||
define float @test1(i1 zeroext %arg) #0 { | ||
%tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00 | ||
%tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00 | ||
%tmp2 = fadd float %tmp, %tmp1 | ||
ret float %tmp2 | ||
; CHECK-LABEL: @test1( | ||
; CHECK: %tmp2 = select i1 %arg, float 6.000000e+00, float 1.500000e+01 | ||
; CHECK-NOT: fadd | ||
; CHECK: ret float %tmp2 | ||
} | ||
|
||
; Tests folding constants from two similar selects that feed a sub | ||
define float @test2(i1 zeroext %arg) #0 { | ||
%tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00 | ||
%tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00 | ||
%tmp2 = fsub float %tmp, %tmp1 | ||
ret float %tmp2 | ||
; CHECK-LABEL: @test2( | ||
; CHECK: %tmp2 = select i1 %arg, float 4.000000e+00, float -3.000000e+00 | ||
; CHECK-NOT: fsub | ||
; CHECK: ret float %tmp2 | ||
} | ||
|
||
; Tests folding constants from two similar selects that feed a mul | ||
define float @test3(i1 zeroext %arg) #0 { | ||
%tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00 | ||
%tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00 | ||
%tmp2 = fmul float %tmp, %tmp1 | ||
ret float %tmp2 | ||
; CHECK-LABEL: @test3( | ||
; CHECK: %tmp2 = select i1 %arg, float 5.000000e+00, float 5.400000e+01 | ||
; CHECK-NOT: fmul | ||
; CHECK: ret float %tmp2 | ||
} | ||
|