| Edward O'Callaghan | e45ac76 | 2009-10-26 22:52:03 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| Dan Gohman | dafa9c6 | 2008-09-16 18:46:06 +0000 | [diff] [blame] | 2 | |
| 3 | ; Instcombine normally would fold the sdiv into the comparison, |
| 4 | ; making "icmp slt i32 %h, 2", but in this case the sdiv has |
| 5 | ; another use, so it wouldn't a big win, and it would also |
| 6 | ; obfuscate an otherise obvious smax pattern to the point where |
| 7 | ; other analyses wouldn't recognize it. |
| 8 | |
| 9 | define i32 @foo(i32 %h) { |
| 10 | %sd = sdiv i32 %h, 2 |
| 11 | %t = icmp slt i32 %sd, 1 |
| 12 | %r = select i1 %t, i32 %sd, i32 1 |
| 13 | ret i32 %r |
| 14 | } |
| 15 | |
| Edward O'Callaghan | e45ac76 | 2009-10-26 22:52:03 +0000 | [diff] [blame] | 16 | ; CHECK: %sd = sdiv i32 %h, 2 |
| 17 | ; CHECK: %t = icmp slt i32 %sd, 1 |
| 18 | ; CHECK: %r = select i1 %t, i32 %sd, i32 1 |
| 19 | ; CHECK: ret i32 %r |
| 20 | |
| Dan Gohman | dafa9c6 | 2008-09-16 18:46:06 +0000 | [diff] [blame] | 21 | define i32 @bar(i32 %h) { |
| 22 | %sd = sdiv i32 %h, 2 |
| 23 | %t = icmp sgt i32 %sd, 1 |
| 24 | %r = select i1 %t, i32 %sd, i32 1 |
| 25 | ret i32 %r |
| 26 | } |
| 27 | |
| Edward O'Callaghan | e45ac76 | 2009-10-26 22:52:03 +0000 | [diff] [blame] | 28 | ; CHECK: %sd = sdiv i32 %h, 2 |
| 29 | ; CHECK: %t = icmp sgt i32 %sd, 1 |
| 30 | ; CHECK: %r = select i1 %t, i32 %sd, i32 1 |
| 31 | ; CHECK: ret i32 %r |
| 32 | |