xref: /aosp_15_r20/external/llvm/test/Transforms/InstCombine/preserve-sminmax.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -instcombine -S | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; Instcombine normally would fold the sdiv into the comparison,
4*9880d681SAndroid Build Coastguard Worker; making "icmp slt i32 %h, 2", but in this case the sdiv has
5*9880d681SAndroid Build Coastguard Worker; another use, so it wouldn't a big win, and it would also
6*9880d681SAndroid Build Coastguard Worker; obfuscate an otherise obvious smax pattern to the point where
7*9880d681SAndroid Build Coastguard Worker; other analyses wouldn't recognize it.
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Workerdefine i32 @foo(i32 %h) {
10*9880d681SAndroid Build Coastguard Worker  %sd = sdiv i32 %h, 2
11*9880d681SAndroid Build Coastguard Worker  %t = icmp slt i32 %sd, 1
12*9880d681SAndroid Build Coastguard Worker  %r = select i1 %t, i32 %sd, i32 1
13*9880d681SAndroid Build Coastguard Worker  ret i32 %r
14*9880d681SAndroid Build Coastguard Worker}
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker; CHECK:  %sd = sdiv i32 %h, 2
17*9880d681SAndroid Build Coastguard Worker; CHECK:  %t = icmp slt i32 %sd, 1
18*9880d681SAndroid Build Coastguard Worker; CHECK:  %r = select i1 %t, i32 %sd, i32 1
19*9880d681SAndroid Build Coastguard Worker; CHECK:  ret i32 %r
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Workerdefine i32 @bar(i32 %h) {
22*9880d681SAndroid Build Coastguard Worker  %sd = sdiv i32 %h, 2
23*9880d681SAndroid Build Coastguard Worker  %t = icmp sgt i32 %sd, 1
24*9880d681SAndroid Build Coastguard Worker  %r = select i1 %t, i32 %sd, i32 1
25*9880d681SAndroid Build Coastguard Worker  ret i32 %r
26*9880d681SAndroid Build Coastguard Worker}
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker; CHECK:  %sd = sdiv i32 %h, 2
29*9880d681SAndroid Build Coastguard Worker; CHECK:  %t = icmp sgt i32 %sd, 1
30*9880d681SAndroid Build Coastguard Worker; CHECK:  %r = select i1 %t, i32 %sd, i32 1
31*9880d681SAndroid Build Coastguard Worker; CHECK:  ret i32 %r
32*9880d681SAndroid Build Coastguard Worker
33