llvm/test/Transforms/InstCombine/pr27236.ll
Sanjay Patel fea0530bd5 [InstCombine] canonicalize min/max constant to select's false value
This is a first step towards canonicalization and improved folding/codegen
for integer min/max as discussed here:
http://lists.llvm.org/pipermail/llvm-dev/2016-November/106868.html

Here, we're just matching the simplest min/max patterns and adjusting the
icmp predicate while swapping the select operands.

I've included FIXME tests in test/Transforms/InstCombine/select_meta.ll
so it's easier to see how this might be extended (corresponds to the TODO
comment in the code). That's also why I'm using matchSelectPattern()
rather than a simpler check; once the backend is patched, we can just 
remove some of the restrictions to allow the obfuscated min/max patterns
in the FIXME tests to be matched.

Differential Revision: https://reviews.llvm.org/D26525


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287585 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-21 22:04:14 +00:00

21 lines
769 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -instcombine < %s | FileCheck %s
define float @test1(i32 %scale) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 %scale, 1
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 %scale, i32 1
; CHECK-NEXT: [[TMP3:%.*]] = sitofp i32 [[TMP2]] to float
; CHECK-NEXT: [[TMP4:%.*]] = icmp sgt i32 [[TMP2]], 0
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP4]], float [[TMP3]], float 0.000000e+00
; CHECK-NEXT: ret float [[SEL]]
;
%tmp1 = icmp sgt i32 1, %scale
%tmp2 = select i1 %tmp1, i32 1, i32 %scale
%tmp3 = sitofp i32 %tmp2 to float
%tmp4 = icmp sgt i32 %tmp2, 0
%sel = select i1 %tmp4, float %tmp3, float 0.000000e+00
ret float %sel
}