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