2016-11-09 02:06:14 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2016-04-09 00:51:49 +08:00
|
|
|
; RUN: opt -S -instcombine < %s | FileCheck %s
|
|
|
|
|
|
|
|
define float @test1(i32 %scale) {
|
2016-11-09 02:06:14 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2017-08-04 20:21:03 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[SCALE:%.*]], 1
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[SCALE]], i32 1
|
2016-11-09 02:06:14 +08:00
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = sitofp i32 [[TMP2]] to float
|
[InstCombine] Canonicalize clamp of float types to minmax in fast mode.
Summary:
This commit allows matchSelectPattern to recognize clamp of float
arguments in the presence of FMF the same way as already done for
integers.
This case is a little different though. With integers, given the
min/max pattern is recognized, DAGBuilder starts selecting MIN/MAX
"automatically". That is not the case for float, because for them only
full FMINNAN/FMINNUM/FMAXNAN/FMAXNUM ISD nodes exist and they do care
about NaNs. On the other hand, some backends (e.g. X86) have only
FMIN/FMAX nodes that do not care about NaNS and the former NAN/NUM
nodes are illegal thus selection is not happening. So I decided to do
such kind of transformation in IR (InstCombiner) instead of
complicating the logic in the backend.
Reviewers: spatel, jmolloy, majnemer, efriedma, craig.topper
Reviewed By: efriedma
Subscribers: hiraditya, javed.absar, n.bozhenov, llvm-commits
Patch by Andrei Elovikov <andrei.elovikov@intel.com>
Differential Revision: https://reviews.llvm.org/D33186
llvm-svn: 310054
2017-08-04 20:22:17 +08:00
|
|
|
; CHECK-NEXT: ret float [[TMP3]]
|
2016-11-09 02:06:14 +08:00
|
|
|
;
|
2017-08-04 20:21:03 +08:00
|
|
|
%1 = icmp sgt i32 1, %scale
|
|
|
|
%2 = select i1 %1, i32 1, i32 %scale
|
|
|
|
%3 = sitofp i32 %2 to float
|
|
|
|
%4 = icmp sgt i32 %2, 0
|
|
|
|
%sel = select i1 %4, float %3, float 0.000000e+00
|
2016-04-09 00:51:49 +08:00
|
|
|
ret float %sel
|
|
|
|
}
|