aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/InstSimplify/floating-point-compare.ll
blob: af48d062b4f6422463c67140d78ab8ba262b3b76 (plain)
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
; RUN: opt < %s -instsimplify -S | FileCheck %s

; These tests choose arbitrarily between float and double,
; and between uge and olt, to give reasonble coverage 
; without combinatorial explosion.

declare float @llvm.fabs.f32(float)
declare float @llvm.sqrt.f32(float)
declare double @llvm.powi.f64(double,i32)
declare float @llvm.exp.f32(float)
declare double @llvm.exp2.f64(double)
declare float @llvm.fma.f32(float,float,float)

declare void @expect_equal(i1,i1)

; CHECK-LABEL: @orderedLessZeroTree(
define i1 @orderedLessZeroTree(float,float,float,float) {
  %square = fmul float %0, %0
  %abs = call float @llvm.fabs.f32(float %1)
  %sqrt = call float @llvm.sqrt.f32(float %2)
  %fma = call float @llvm.fma.f32(float %3, float %3, float %sqrt)
  %div = fdiv float %square, %abs
  %rem = frem float %sqrt, %fma
  %add = fadd float %div, %rem
  %uge = fcmp uge float %add, 0.000000e+00
; CHECK: ret i1 true
  ret i1 %uge
}

; CHECK-LABEL: @orderedLessZeroExpExt(
define i1 @orderedLessZeroExpExt(float) {
  %a = call float @llvm.exp.f32(float %0)
  %b = fpext float %a to double
  %uge = fcmp uge double %b, 0.000000e+00
; CHECK: ret i1 true
  ret i1 %uge
}

; CHECK-LABEL: @orderedLessZeroExp2Trunc(
define i1 @orderedLessZeroExp2Trunc(double) {
  %a = call double @llvm.exp2.f64(double %0)
  %b = fptrunc double %a to float
  %olt = fcmp olt float %b, 0.000000e+00
; CHECK: ret i1 false
  ret i1 %olt
}

; CHECK-LABEL: @orderedLessZeroPowi(
define i1 @orderedLessZeroPowi(double,double) {
  ; Even constant exponent
  %a = call double @llvm.powi.f64(double %0, i32 2)
  %square = fmul double %1, %1
  ; Odd constant exponent with provably non-negative base
  %b = call double @llvm.powi.f64(double %square, i32 3)
  %c = fadd double %a, %b
  %olt = fcmp olt double %b, 0.000000e+00
; CHECK: ret i1 false
  ret i1 %olt
}