Home | History | Annotate | Download | only in InstCombine
      1 ; Test that the exp2 library call simplifier works correctly.
      2 ;
      3 ; RUN: opt < %s -instcombine -S | FileCheck %s -check-prefix=CHECK -check-prefix=INTRINSIC -check-prefix=LDEXP -check-prefix=LDEXPF
      4 ; RUN: opt < %s -instcombine -S -mtriple=i386-pc-win32 | FileCheck %s -check-prefix=INTRINSIC -check-prefix=LDEXP -check-prefix=NOLDEXPF
      5 ; RUN: opt < %s -instcombine -S -mtriple=amdgcn-unknown-unknown | FileCheck %s -check-prefix=INTRINSIC -check-prefix=NOLDEXP -check-prefix=NOLDEXPF
      6 
      7 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
      8 
      9 declare double @exp2(double)
     10 declare float @exp2f(float)
     11 
     12 ; Check exp2(sitofp(x)) -> ldexp(1.0, sext(x)).
     13 
     14 define double @test_simplify1(i32 %x) {
     15 ; CHECK-LABEL: @test_simplify1(
     16   %conv = sitofp i32 %x to double
     17   %ret = call double @exp2(double %conv)
     18 ; CHECK: call double @ldexp
     19   ret double %ret
     20 }
     21 
     22 define double @test_simplify2(i16 signext %x) {
     23 ; CHECK-LABEL: @test_simplify2(
     24   %conv = sitofp i16 %x to double
     25   %ret = call double @exp2(double %conv)
     26 ; CHECK: call double @ldexp
     27   ret double %ret
     28 }
     29 
     30 define double @test_simplify3(i8 signext %x) {
     31 ; CHECK-LABEL: @test_simplify3(
     32   %conv = sitofp i8 %x to double
     33   %ret = call double @exp2(double %conv)
     34 ; CHECK: call double @ldexp
     35   ret double %ret
     36 }
     37 
     38 define float @test_simplify4(i32 %x) {
     39 ; CHECK-LABEL: @test_simplify4(
     40   %conv = sitofp i32 %x to float
     41   %ret = call float @exp2f(float %conv)
     42 ; CHECK: call float @ldexpf
     43   ret float %ret
     44 }
     45 
     46 ; Check exp2(uitofp(x)) -> ldexp(1.0, zext(x)).
     47 
     48 define double @test_no_simplify1(i32 %x) {
     49 ; CHECK-LABEL: @test_no_simplify1(
     50   %conv = uitofp i32 %x to double
     51   %ret = call double @exp2(double %conv)
     52 ; CHECK: call double @exp2
     53   ret double %ret
     54 }
     55 
     56 define double @test_simplify6(i16 zeroext %x) {
     57 ; CHECK-LABEL: @test_simplify6(
     58   %conv = uitofp i16 %x to double
     59   %ret = call double @exp2(double %conv)
     60 ; CHECK: call double @ldexp
     61   ret double %ret
     62 }
     63 
     64 define double @test_simplify7(i8 zeroext %x) {
     65 ; CHECK-LABEL: @test_simplify7(
     66   %conv = uitofp i8 %x to double
     67   %ret = call double @exp2(double %conv)
     68 ; CHECK: call double @ldexp
     69   ret double %ret
     70 }
     71 
     72 define float @test_simplify8(i8 zeroext %x) {
     73 ; CHECK-LABEL: @test_simplify8(
     74   %conv = uitofp i8 %x to float
     75   %ret = call float @exp2f(float %conv)
     76 ; CHECK: call float @ldexpf
     77   ret float %ret
     78 }
     79 
     80 declare double @llvm.exp2.f64(double)
     81 declare float @llvm.exp2.f32(float)
     82 
     83 define double @test_simplify9(i8 zeroext %x) {
     84 ; INTRINSIC-LABEL: @test_simplify9(
     85   %conv = uitofp i8 %x to double
     86   %ret = call double @llvm.exp2.f64(double %conv)
     87 ; LDEXP: call double @ldexp
     88 ; NOLDEXP-NOT: call double @ldexp
     89   ret double %ret
     90 }
     91 
     92 define float @test_simplify10(i8 zeroext %x) {
     93 ; INTRINSIC-LABEL: @test_simplify10(
     94   %conv = uitofp i8 %x to float
     95   %ret = call float @llvm.exp2.f32(float %conv)
     96 ; LDEXPF: call float @ldexpf
     97 ; NOLDEXPF-NOT: call float @ldexpf
     98   ret float %ret
     99 }
    100