Craig Topper | 2b54bae | 2017-06-04 08:21:58 +0000 | [diff] [blame^] | 1 | ; REQUIRES: x86-registered-target |
Max Kazantsev | 4145032 | 2017-05-26 06:47:04 +0000 | [diff] [blame] | 2 | ; RUN: opt -loop-reduce -S < %s | FileCheck %s |
| 3 | |
| 4 | ; Strength reduction analysis here relies on IV Users analysis, that |
| 5 | ; only finds users among instructions with types that are treated as |
| 6 | ; legal by the data layout. When running this test on pure non-x86 |
| 7 | ; configs (for example, ARM 64), it gets confused with the target |
| 8 | ; triple and uses a default data layout instead. This default layout |
| 9 | ; does not have any legal types (even i32), so the transformation |
| 10 | ; does not happen. |
| 11 | |
| 12 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" |
| 13 | target triple = "x86_64-apple-macosx" |
| 14 | |
| 15 | ; PR15470: LSR miscompile. The test2 function should return '1'. |
| 16 | ; |
| 17 | ; SCEV expander cannot expand quadratic recurrences outside of the |
| 18 | ; loop. This recurrence depends on %sub.us, so can't be expanded. |
| 19 | ; We cannot fold SCEVUnknown (sub.us) with recurrences since it is |
| 20 | ; declared after the loop. |
| 21 | ; |
| 22 | ; CHECK-LABEL: @test2 |
| 23 | ; CHECK-LABEL: test2.loop: |
| 24 | ; CHECK: %lsr.iv1 = phi i32 [ %lsr.iv.next2, %test2.loop ], [ -16777216, %entry ] |
| 25 | ; CHECK: %lsr.iv = phi i32 [ %lsr.iv.next, %test2.loop ], [ -1, %entry ] |
| 26 | ; CHECK: %lsr.iv.next = add nsw i32 %lsr.iv, 1 |
| 27 | ; CHECK: %lsr.iv.next2 = add nsw i32 %lsr.iv1, 16777216 |
| 28 | ; |
| 29 | ; CHECK-LABEL: for.end: |
| 30 | ; CHECK: %tobool.us = icmp eq i32 %lsr.iv.next2, 0 |
| 31 | ; CHECK: %sub.us = select i1 %tobool.us, i32 0, i32 0 |
| 32 | ; CHECK: %1 = sub i32 0, %sub.us |
| 33 | ; CHECK: %2 = add i32 %1, %lsr.iv.next |
| 34 | ; CHECK: %sext.us = mul i32 %lsr.iv.next2, %2 |
| 35 | ; CHECK: %f = ashr i32 %sext.us, 24 |
| 36 | ; CHECK: ret i32 %f |
| 37 | define i32 @test2() { |
| 38 | entry: |
| 39 | br label %test2.loop |
| 40 | |
| 41 | test2.loop: |
| 42 | %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test2.loop ] |
| 43 | %inc11.us = add nsw i32 %inc1115.us, 1 |
| 44 | %cmp.us = icmp slt i32 %inc11.us, 2 |
| 45 | br i1 %cmp.us, label %test2.loop, label %for.end |
| 46 | |
| 47 | for.end: |
| 48 | %tobool.us = icmp eq i32 %inc1115.us, 0 |
| 49 | %sub.us = select i1 %tobool.us, i32 0, i32 0 |
| 50 | %mul.us = shl i32 %inc1115.us, 24 |
| 51 | %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us |
| 52 | %sext.us = mul i32 %mul.us, %sub.cond.us |
| 53 | %f = ashr i32 %sext.us, 24 |
| 54 | br label %exit |
| 55 | |
| 56 | exit: |
| 57 | ret i32 %f |
| 58 | } |