xref: /llvm-project/llvm/test/Transforms/PhaseOrdering/generate-fabs.ll (revision cd1e6a587be6352f63f180b1ff5e0a348a8da444)
1*cd1e6a58SYashwant Singh; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2*cd1e6a58SYashwant Singh; RUN: opt -passes='default<O1>' -S < %s | FileCheck %s
3*cd1e6a58SYashwant Singh
4*cd1e6a58SYashwant Singh; Following test must generate fabs intrinsic. It goes through following stages
5*cd1e6a58SYashwant Singh; 1. SROA propagates the nsz function attribute on the phi node.
6*cd1e6a58SYashwant Singh; 2. SimplifyCFG pass converts phi node to select.
7*cd1e6a58SYashwant Singh; 3. InstCombine converts select with nsz flag into fabs intrinsic.
8*cd1e6a58SYashwant Singh
9*cd1e6a58SYashwant Singhdefine double @fabs_fcmp_olt_nsz_func_attr(double %0, double %1) "no-signed-zeros-fp-math"="true" {
10*cd1e6a58SYashwant Singh; CHECK-LABEL: define double @fabs_fcmp_olt_nsz_func_attr(
11*cd1e6a58SYashwant Singh; CHECK-SAME: double [[TMP0:%.*]], double [[TMP1:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
12*cd1e6a58SYashwant Singh; CHECK-NEXT:  [[ENTRY:.*:]]
13*cd1e6a58SYashwant Singh; CHECK-NEXT:    [[X_0:%.*]] = tail call nnan nsz double @llvm.fabs.f64(double [[TMP0]])
14*cd1e6a58SYashwant Singh; CHECK-NEXT:    ret double [[X_0]]
15*cd1e6a58SYashwant Singhentry:
16*cd1e6a58SYashwant Singh  %x = alloca double
17*cd1e6a58SYashwant Singh  store	double %0, ptr %x
18*cd1e6a58SYashwant Singh  %cmp = fcmp nnan nsz olt double %0, 0.000000e+00
19*cd1e6a58SYashwant Singh  br i1 %cmp, label %if.then, label %return
20*cd1e6a58SYashwant Singh
21*cd1e6a58SYashwant Singhif.then:                         ; preds = %entry
22*cd1e6a58SYashwant Singh  %fneg = fneg nnan nsz double %0
23*cd1e6a58SYashwant Singh  store double %fneg, ptr %x
24*cd1e6a58SYashwant Singh  br label %return
25*cd1e6a58SYashwant Singh
26*cd1e6a58SYashwant Singhreturn:                          ; preds = %entry, %if.then
27*cd1e6a58SYashwant Singh  %ret = load double, ptr %x
28*cd1e6a58SYashwant Singh  ret double %ret
29*cd1e6a58SYashwant Singh}
30