xref: /llvm-project/llvm/test/Transforms/InstCombine/sqrt-nofast.ll (revision 4ab40eca080965c65802710e39adbb78c4ce7bde)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3
4; Check that we skip transformations if the attribute unsafe-fp-math
5; is not set.
6
7define float @mysqrt(float %x, float %y) #0 {
8; CHECK-LABEL: @mysqrt(
9; CHECK-NEXT:  entry:
10; CHECK-NEXT:    [[MUL:%.*]] = fmul fast float [[X:%.*]], [[X]]
11; CHECK-NEXT:    [[TMP0:%.*]] = call float @llvm.sqrt.f32(float [[MUL]])
12; CHECK-NEXT:    ret float [[TMP0]]
13;
14entry:
15  %x.addr = alloca float, align 4
16  %y.addr = alloca float, align 4
17  store float %x, ptr %x.addr, align 4
18  store float %y, ptr %y.addr, align 4
19  %0 = load float, ptr %x.addr, align 4
20  %1 = load float, ptr %x.addr, align 4
21  %mul = fmul fast float %0, %1
22  %2 = call float @llvm.sqrt.f32(float %mul)
23  ret float %2
24}
25
26declare float @llvm.sqrt.f32(float) #1
27
28; The call below is to a function called "sqrtf", but its type is double.
29; Assume it is a user function rather than a libm function, and so don't
30; transform it.
31
32define double @fake_sqrt(double %a, double %b) {
33; CHECK-LABEL: @fake_sqrt(
34; CHECK-NEXT:    [[C:%.*]] = fmul fast double [[A:%.*]], [[A]]
35; CHECK-NEXT:    [[E:%.*]] = call fast double @sqrtf(double [[C]]) #[[ATTR1:[0-9]+]]
36; CHECK-NEXT:    ret double [[E]]
37;
38  %c = fmul fast double %a, %a
39  %e = call fast double @sqrtf(double %c) readnone
40  ret double %e
41}
42
43; Standard sqrtf takes and returns float.  The following is not it.
44declare double @sqrtf(double) readnone
45