brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · 7cdfdcd Raw
140 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"5 6; Tests folding constants from two similar selects that feed a add7 8define float @test1a(i1 zeroext %arg) #0 {9; CHECK-LABEL: @test1a(10; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[ARG:%.*]], float 6.000000e+00, float 1.500000e+0111; CHECK-NEXT:    ret float [[TMP2]]12;13  %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+0014  %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+0015  %tmp2 = fadd float %tmp, %tmp116  ret float %tmp217}18 19; Tests folding multiple expression constants from similar selects that feed a adds20 21define float @test1b(i1 zeroext %arg) #0 {22; CHECK-LABEL: @test1b(23; CHECK-NEXT:    [[TMP5:%.*]] = select i1 [[ARG:%.*]], float 7.250000e+00, float 2.800000e+0124; CHECK-NEXT:    ret float [[TMP5]]25;26  %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+0027  %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+0028  %tmp2 = select i1 %arg, float 2.500000e-01, float 4.000000e+0029  %tmp3 = fadd float %tmp, %tmp130  %tmp4 = fadd float %tmp2, %tmp131  %tmp5 = fadd float %tmp4, %tmp332  ret float %tmp533}34 35; Tests folding constants from two similar selects that feed a sub36 37define float @test2(i1 zeroext %arg) #0 {38; CHECK-LABEL: @test2(39; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[ARG:%.*]], float 4.000000e+00, float -3.000000e+0040; CHECK-NEXT:    ret float [[TMP2]]41;42  %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+0043  %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+0044  %tmp2 = fsub float %tmp, %tmp145  ret float %tmp246}47 48; Tests folding constants from two similar selects that feed a mul49 50define float @test3(i1 zeroext %arg) #0 {51; CHECK-LABEL: @test3(52; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[ARG:%.*]], float 5.000000e+00, float 5.400000e+0153; CHECK-NEXT:    ret float [[TMP2]]54;55  %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+0056  %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+0057  %tmp2 = fmul float %tmp, %tmp158  ret float %tmp259}60 61declare void @use_float(float)62 63; Tests folding constants if the selects have multiple uses but64; we can fold away the binary op with a select.65 66define float @test4(i1 zeroext %arg) #0 {67; CHECK-LABEL: @test4(68; CHECK-NEXT:    [[TMP:%.*]] = select i1 [[ARG:%.*]], float 5.000000e+00, float 6.000000e+0069; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[ARG]], float 5.000000e+00, float 5.400000e+0170; CHECK-NEXT:    call void @use_float(float [[TMP]])71; CHECK-NEXT:    ret float [[TMP2]]72;73  %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+0074  %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+0075  %tmp2 = fmul float %tmp, %tmp176  call void @use_float(float %tmp)77  ret float %tmp278}79 80; Tests not folding constants if we cannot fold away any of the selects.81 82define float @test5(i1 zeroext %arg, float %div) {83; CHECK-LABEL: @test5(84; CHECK-NEXT:    [[TMP:%.*]] = select i1 [[ARG:%.*]], float [[DIV:%.*]], float 5.000000e+0085; CHECK-NEXT:    [[MUL:%.*]] = fmul contract float [[TMP]], [[TMP]]86; CHECK-NEXT:    call void @use_float(float [[TMP]])87; CHECK-NEXT:    ret float [[MUL]]88;89  %tmp = select i1 %arg, float %div, float 5.000000e+0090  %mul = fmul contract float %tmp, %tmp91  call void @use_float(float %tmp)92  ret float %mul93}94 95define float @fmul_nnan_nsz(i1 %cond, float %val) {96; CHECK-LABEL: @fmul_nnan_nsz(97; CHECK-NEXT:    ret float 0.000000e+0098;99  %lhs = select i1 %cond, float %val, float +0.0100  %rhs = select i1 %cond, float -0.0, float %val101  %mul = fmul nnan nsz float %lhs, %rhs102  ret float %mul103}104 105define <2 x float> @fadd_nsz(<2 x i1> %cond, <2 x float> %val) {106; CHECK-LABEL: @fadd_nsz(107; CHECK-NEXT:    ret <2 x float> [[VAL:%.*]]108;109  %lhs = select <2 x i1> %cond, <2 x float> %val, <2 x float> <float +0.0, float +0.0>110  %rhs = select <2 x i1> %cond, <2 x float> <float +0.0, float +0.0>, <2 x float> %val111  %add = fadd nsz <2 x float> %lhs, %rhs112  ret <2 x float> %add113}114 115define double @fsub_nnan(i1 %cond, double %val, double %val2) {116; CHECK-LABEL: @fsub_nnan(117; CHECK-NEXT:    [[TMP1:%.*]] = fadd nnan double [[VAL2:%.*]], -7.000000e+00118; CHECK-NEXT:    [[ADD:%.*]] = select nnan i1 [[COND:%.*]], double 0.000000e+00, double [[TMP1]]119; CHECK-NEXT:    ret double [[ADD]]120;121  %lhs = select i1 %cond, double %val, double %val2122  %rhs = select i1 %cond, double %val, double 7.0123  %add = fsub nnan double %lhs, %rhs124  ret double %add125}126 127; TODO combine selects feeding fdiv like we do for fmul, fadd and fsub128define double @fdiv_nnan_nsz(i1 %cond, double %val, double %val2) {129; CHECK-LABEL: @fdiv_nnan_nsz(130; CHECK-NEXT:    [[LHS:%.*]] = select i1 [[COND:%.*]], double [[VAL2:%.*]], double 0.000000e+00131; CHECK-NEXT:    [[RHS:%.*]] = select i1 [[COND]], double 4.200000e+01, double [[VAL:%.*]]132; CHECK-NEXT:    [[ADD:%.*]] = fdiv nnan nsz double [[LHS]], [[RHS]]133; CHECK-NEXT:    ret double [[ADD]]134;135  %lhs = select i1 %cond, double %val2, double 0.0136  %rhs = select i1 %cond, double 42.0, double %val137  %add = fdiv nnan nsz double %lhs, %rhs138  ret double %add139}140