File: icmp-div-constant.ll

package info (click to toggle)
llvm-toolchain-5.0 1:5.0.1-2~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 553,688 kB
  • sloc: cpp: 2,878,786; ansic: 584,110; asm: 246,252; python: 124,751; objc: 106,925; sh: 21,542; lisp: 8,628; pascal: 5,885; ml: 5,544; perl: 5,312; makefile: 2,208; cs: 2,022; xml: 686; php: 212; csh: 117
file content (93 lines) | stat: -rw-r--r-- 2,602 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s

; PR30281 - https://llvm.org/bugs/show_bug.cgi?id=30281

; All of these tests contain foldable division-by-constant instructions, but we
; can't assert that those folds have occurred before we process the later icmp.

define i32 @icmp_div(i16 %a, i16 %c) {
; CHECK-LABEL: @icmp_div(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i16 %a, 0
; CHECK-NEXT:    br i1 [[TOBOOL]], label %then, label %exit
; CHECK:       then:
; CHECK-NEXT:    [[NOT_CMP:%.*]] = icmp eq i16 %c, 0
; CHECK-NEXT:    [[PHITMP1:%.*]] = sext i1 [[NOT_CMP]] to i32
; CHECK-NEXT:    br label %exit
; CHECK:       exit:
; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, %entry ], [ [[PHITMP1]], %then ]
; CHECK-NEXT:    ret i32 [[PHI]]
;
entry:
  %tobool = icmp eq i16 %a, 0
  br i1 %tobool, label %then, label %exit

then:
  %div = sdiv i16 %c, -1
  %cmp = icmp ne i16 %div, 0
  br label %exit

exit:
  %phi = phi i1 [ false, %entry ], [ %cmp, %then ]
  %zext = zext i1 %phi to i32
  %add = add nsw i32 %zext, -1
  ret i32 %add
}

define i32 @icmp_div2(i16 %a, i16 %c) {
; CHECK-LABEL: @icmp_div2(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i16 %a, 0
; CHECK-NEXT:    br i1 [[TOBOOL]], label %then, label %exit
; CHECK:       then:
; CHECK-NEXT:    br label %exit
; CHECK:       exit:
; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, %entry ], [ 0, %then ]
; CHECK-NEXT:    ret i32 [[PHI]]
;
entry:
  %tobool = icmp eq i16 %a, 0
  br i1 %tobool, label %then, label %exit

then:
  %div = sdiv i16 %c, 0
  %cmp = icmp ne i16 %div, 0
  br label %exit

exit:
  %phi = phi i1 [ false, %entry ], [ %cmp, %then ]
  %zext = zext i1 %phi to i32
  %add = add nsw i32 %zext, -1
  ret i32 %add
}

define i32 @icmp_div3(i16 %a, i16 %c) {
; CHECK-LABEL: @icmp_div3(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i16 %a, 0
; CHECK-NEXT:    br i1 [[TOBOOL]], label %then, label %exit
; CHECK:       then:
; CHECK-NEXT:    [[NOT_CMP:%.*]] = icmp eq i16 %c, 0
; CHECK-NEXT:    [[PHITMP1:%.*]] = sext i1 [[NOT_CMP]] to i32
; CHECK-NEXT:    br label %exit
; CHECK:       exit:
; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, %entry ], [ [[PHITMP1]], %then ]
; CHECK-NEXT:    ret i32 [[PHI]]
;
entry:
  %tobool = icmp eq i16 %a, 0
  br i1 %tobool, label %then, label %exit

then:
  %div = sdiv i16 %c, 1
  %cmp = icmp ne i16 %div, 0
  br label %exit

exit:
  %phi = phi i1 [ false, %entry ], [ %cmp, %then ]
  %zext = zext i1 %phi to i32
  %add = add nsw i32 %zext, -1
  ret i32 %add
}