mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-16 11:30:51 +00:00
b5c82c079a
This patch folds fcmp in some cases of interest in Julia. The patch adds a function CannotBeOrderedLessThanZero that returns true if a value is provably not less than zero. I.e. the function returns true if the value is provably -0, +0, positive, or a NaN. The patch extends InstructionSimplify.cpp to fold instances of fcmp where: - the predicate is olt or uge - the first operand is provably not less than zero - the second operand is zero The motivation for handling these cases optimizing away domain checks for sqrt in Julia for common idioms such as sqrt(x*x+y*y).. http://reviews.llvm.org/D6972 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227298 91177308-0d34-0410-b5e6-96231b3b80d8
61 lines
1.8 KiB
LLVM
61 lines
1.8 KiB
LLVM
; 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
|
|
}
|
|
|