[llvm] [Attributor][FIX] Replace AANoFPClass MBEC propagation (PR #91030)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 04:49:20 PDT 2024


================
@@ -0,0 +1,357 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes
+; RUN: opt -passes=attributor -S < %s | FileCheck %s --check-prefixes=CHECK
+
+; Verify we do not derive 'nofpclass(inf zero sub norm)' for the argument __x.
+; See https://github.com/llvm/llvm-project/issues/78507
+
+source_filename = "llvm-link"
+target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
+target triple = "amdgcn-amd-amdhsa"
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare double @llvm.ldexp.f64.i32(double, i32) #0
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare double @llvm.amdgcn.fract.f64(double) #0
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare double @llvm.fma.f64(double, double, double) #0
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare double @llvm.fabs.f64(double) #0
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare double @llvm.rint.f64(double) #0
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare double @llvm.amdgcn.trig.preop.f64(double, i32) #0
+
+; Function Attrs: alwaysinline mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+define hidden double @sin(double noundef %__x) local_unnamed_addr #1 {
+; CHECK: Function Attrs: alwaysinline mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define {{[^@]+}}@sin
+; CHECK-SAME: (double noundef [[__X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call double @llvm.fabs.f64(double noundef [[__X]])
+; CHECK-NEXT:    [[TMP1:%.*]] = fcmp olt double [[TMP0]], 0x41D0000000000000
+; CHECK-NEXT:    br i1 [[TMP1]], label [[TMP2:%.*]], label [[TMP21:%.*]]
+; CHECK:       2:
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul double [[TMP0]], 0x3FE45F306DC9C883
+; CHECK-NEXT:    [[TMP4:%.*]] = tail call double @llvm.rint.f64(double noundef [[TMP3]])
+; CHECK-NEXT:    [[TMP5:%.*]] = tail call double @llvm.fma.f64(double noundef [[TMP4]], double noundef 0xBFF921FB54442D18, double noundef [[TMP0]])
+; CHECK-NEXT:    [[TMP6:%.*]] = tail call double @llvm.fma.f64(double noundef [[TMP4]], double noundef 0xBC91A62633145C00, double noundef [[TMP5]])
+; CHECK-NEXT:    [[TMP7:%.*]] = fmul double [[TMP4]], 0x3C91A62633145C00
+; CHECK-NEXT:    [[TMP8:%.*]] = fneg double [[TMP7]]
+; CHECK-NEXT:    [[TMP9:%.*]] = tail call double @llvm.fma.f64(double noundef [[TMP4]], double noundef 0x3C91A62633145C00, double noundef [[TMP8]])
+; CHECK-NEXT:    [[TMP10:%.*]] = fsub double [[TMP5]], [[TMP7]]
+; CHECK-NEXT:    [[TMP11:%.*]] = fsub double [[TMP5]], [[TMP10]]
+; CHECK-NEXT:    [[TMP12:%.*]] = fsub double [[TMP11]], [[TMP7]]
+; CHECK-NEXT:    [[TMP13:%.*]] = fsub double [[TMP10]], [[TMP6]]
+; CHECK-NEXT:    [[TMP14:%.*]] = fadd double [[TMP13]], [[TMP12]]
+; CHECK-NEXT:    [[TMP15:%.*]] = fsub double [[TMP14]], [[TMP9]]
+; CHECK-NEXT:    [[TMP16:%.*]] = tail call double @llvm.fma.f64(double noundef [[TMP4]], double noundef 0xB97B839A252049C0, double [[TMP15]])
+; CHECK-NEXT:    [[TMP17:%.*]] = fadd double [[TMP6]], [[TMP16]]
+; CHECK-NEXT:    [[TMP18:%.*]] = fsub double [[TMP17]], [[TMP6]]
+; CHECK-NEXT:    [[TMP19:%.*]] = fsub double [[TMP16]], [[TMP18]]
+; CHECK-NEXT:    [[TMP20:%.*]] = fptosi double [[TMP4]] to i32
+; CHECK-NEXT:    br label [[__OCML_SIN_F64_EXIT:%.*]]
+; CHECK:       21:
+; CHECK-NEXT:    [[TMP22:%.*]] = tail call double @llvm.amdgcn.trig.preop.f64(double noundef [[TMP0]], i32 noundef 0)
+; CHECK-NEXT:    [[TMP23:%.*]] = tail call double @llvm.amdgcn.trig.preop.f64(double noundef [[TMP0]], i32 noundef 1)
+; CHECK-NEXT:    [[TMP24:%.*]] = tail call double @llvm.amdgcn.trig.preop.f64(double noundef [[TMP0]], i32 noundef 2)
+; CHECK-NEXT:    [[TMP25:%.*]] = fcmp oge double [[TMP0]], 0x7B00000000000000
+; CHECK-NEXT:    [[TMP26:%.*]] = tail call double @llvm.ldexp.f64.i32(double noundef [[TMP0]], i32 noundef -128)
+; CHECK-NEXT:    [[TMP27:%.*]] = select i1 [[TMP25]], double [[TMP26]], double [[TMP0]]
+; CHECK-NEXT:    [[TMP28:%.*]] = fmul double [[TMP24]], [[TMP27]]
+; CHECK-NEXT:    [[TMP29:%.*]] = fneg double [[TMP28]]
+; CHECK-NEXT:    [[TMP30:%.*]] = tail call double @llvm.fma.f64(double [[TMP24]], double noundef [[TMP27]], double [[TMP29]])
+; CHECK-NEXT:    [[TMP31:%.*]] = fmul double [[TMP23]], [[TMP27]]
+; CHECK-NEXT:    [[TMP32:%.*]] = fneg double [[TMP31]]
+; CHECK-NEXT:    [[TMP33:%.*]] = tail call double @llvm.fma.f64(double [[TMP23]], double noundef [[TMP27]], double [[TMP32]])
+; CHECK-NEXT:    [[TMP34:%.*]] = fmul double [[TMP22]], [[TMP27]]
+; CHECK-NEXT:    [[TMP35:%.*]] = fneg double [[TMP34]]
+; CHECK-NEXT:    [[TMP36:%.*]] = tail call double @llvm.fma.f64(double [[TMP22]], double noundef [[TMP27]], double [[TMP35]])
+; CHECK-NEXT:    [[TMP37:%.*]] = fadd double [[TMP31]], [[TMP36]]
+; CHECK-NEXT:    [[TMP38:%.*]] = fsub double [[TMP37]], [[TMP31]]
+; CHECK-NEXT:    [[TMP39:%.*]] = fsub double [[TMP37]], [[TMP38]]
+; CHECK-NEXT:    [[TMP40:%.*]] = fsub double [[TMP36]], [[TMP38]]
+; CHECK-NEXT:    [[TMP41:%.*]] = fsub double [[TMP31]], [[TMP39]]
+; CHECK-NEXT:    [[TMP42:%.*]] = fadd double [[TMP40]], [[TMP41]]
+; CHECK-NEXT:    [[TMP43:%.*]] = fadd double [[TMP28]], [[TMP33]]
+; CHECK-NEXT:    [[TMP44:%.*]] = fsub double [[TMP43]], [[TMP28]]
+; CHECK-NEXT:    [[TMP45:%.*]] = fsub double [[TMP43]], [[TMP44]]
+; CHECK-NEXT:    [[TMP46:%.*]] = fsub double [[TMP33]], [[TMP44]]
+; CHECK-NEXT:    [[TMP47:%.*]] = fsub double [[TMP28]], [[TMP45]]
+; CHECK-NEXT:    [[TMP48:%.*]] = fadd double [[TMP46]], [[TMP47]]
+; CHECK-NEXT:    [[TMP49:%.*]] = fadd double [[TMP43]], [[TMP42]]
+; CHECK-NEXT:    [[TMP50:%.*]] = fsub double [[TMP49]], [[TMP43]]
+; CHECK-NEXT:    [[TMP51:%.*]] = fsub double [[TMP49]], [[TMP50]]
+; CHECK-NEXT:    [[TMP52:%.*]] = fsub double [[TMP42]], [[TMP50]]
+; CHECK-NEXT:    [[TMP53:%.*]] = fsub double [[TMP43]], [[TMP51]]
+; CHECK-NEXT:    [[TMP54:%.*]] = fadd double [[TMP52]], [[TMP53]]
+; CHECK-NEXT:    [[TMP55:%.*]] = fadd double [[TMP48]], [[TMP54]]
+; CHECK-NEXT:    [[TMP56:%.*]] = fadd double [[TMP30]], [[TMP55]]
+; CHECK-NEXT:    [[TMP57:%.*]] = fadd double [[TMP34]], [[TMP37]]
+; CHECK-NEXT:    [[TMP58:%.*]] = fsub double [[TMP57]], [[TMP34]]
+; CHECK-NEXT:    [[TMP59:%.*]] = fsub double [[TMP37]], [[TMP58]]
+; CHECK-NEXT:    [[TMP60:%.*]] = fadd double [[TMP59]], [[TMP49]]
+; CHECK-NEXT:    [[TMP61:%.*]] = fsub double [[TMP60]], [[TMP59]]
+; CHECK-NEXT:    [[TMP62:%.*]] = fsub double [[TMP49]], [[TMP61]]
+; CHECK-NEXT:    [[TMP63:%.*]] = fadd double [[TMP62]], [[TMP56]]
+; CHECK-NEXT:    [[TMP64:%.*]] = tail call double @llvm.ldexp.f64.i32(double [[TMP57]], i32 noundef -2)
+; CHECK-NEXT:    [[TMP65:%.*]] = tail call double @llvm.amdgcn.fract.f64(double [[TMP64]])
+; CHECK-NEXT:    [[TMP66:%.*]] = tail call double @llvm.fabs.f64(double [[TMP64]]) #[[ATTR2:[0-9]+]]
+; CHECK-NEXT:    [[TMP67:%.*]] = fcmp oeq double [[TMP66]], 0x7FF0000000000000
+; CHECK-NEXT:    [[TMP68:%.*]] = select i1 [[TMP67]], double 0.000000e+00, double [[TMP65]]
+; CHECK-NEXT:    [[TMP69:%.*]] = tail call double @llvm.ldexp.f64.i32(double [[TMP68]], i32 noundef 2)
+; CHECK-NEXT:    [[TMP70:%.*]] = fadd double [[TMP69]], [[TMP60]]
+; CHECK-NEXT:    [[TMP71:%.*]] = fcmp olt double [[TMP70]], 0.000000e+00
+; CHECK-NEXT:    [[TMP72:%.*]] = select i1 [[TMP71]], double 4.000000e+00, double 0.000000e+00
+; CHECK-NEXT:    [[TMP73:%.*]] = fadd double [[TMP69]], [[TMP72]]
+; CHECK-NEXT:    [[TMP74:%.*]] = fadd double [[TMP60]], [[TMP73]]
+; CHECK-NEXT:    [[TMP75:%.*]] = fptosi double [[TMP74]] to i32
+; CHECK-NEXT:    [[TMP76:%.*]] = sitofp i32 [[TMP75]] to double
+; CHECK-NEXT:    [[TMP77:%.*]] = fsub double [[TMP73]], [[TMP76]]
+; CHECK-NEXT:    [[TMP78:%.*]] = fadd double [[TMP60]], [[TMP77]]
+; CHECK-NEXT:    [[TMP79:%.*]] = fsub double [[TMP78]], [[TMP77]]
+; CHECK-NEXT:    [[TMP80:%.*]] = fsub double [[TMP60]], [[TMP79]]
+; CHECK-NEXT:    [[TMP81:%.*]] = fadd double [[TMP63]], [[TMP80]]
+; CHECK-NEXT:    [[TMP82:%.*]] = fcmp oge double [[TMP78]], 5.000000e-01
+; CHECK-NEXT:    [[TMP83:%.*]] = zext i1 [[TMP82]] to i32
+; CHECK-NEXT:    [[TMP84:%.*]] = add nsw i32 [[TMP83]], [[TMP75]]
+; CHECK-NEXT:    [[TMP85:%.*]] = select i1 [[TMP82]], double 1.000000e+00, double 0.000000e+00
+; CHECK-NEXT:    [[TMP86:%.*]] = fsub double [[TMP78]], [[TMP85]]
+; CHECK-NEXT:    [[TMP87:%.*]] = fadd double [[TMP86]], [[TMP81]]
+; CHECK-NEXT:    [[TMP88:%.*]] = fsub double [[TMP87]], [[TMP86]]
+; CHECK-NEXT:    [[TMP89:%.*]] = fsub double [[TMP81]], [[TMP88]]
+; CHECK-NEXT:    [[TMP90:%.*]] = fmul double [[TMP87]], 0x3FF921FB54442D18
+; CHECK-NEXT:    [[TMP91:%.*]] = fneg double [[TMP90]]
+; CHECK-NEXT:    [[TMP92:%.*]] = tail call double @llvm.fma.f64(double [[TMP87]], double noundef 0x3FF921FB54442D18, double [[TMP91]])
+; CHECK-NEXT:    [[TMP93:%.*]] = tail call double @llvm.fma.f64(double [[TMP87]], double noundef 0x3C91A62633145C07, double [[TMP92]])
+; CHECK-NEXT:    [[TMP94:%.*]] = tail call double @llvm.fma.f64(double [[TMP89]], double noundef 0x3FF921FB54442D18, double [[TMP93]])
+; CHECK-NEXT:    [[TMP95:%.*]] = fadd double [[TMP90]], [[TMP94]]
+; CHECK-NEXT:    [[TMP96:%.*]] = fsub double [[TMP95]], [[TMP90]]
+; CHECK-NEXT:    [[TMP97:%.*]] = fsub double [[TMP94]], [[TMP96]]
+; CHECK-NEXT:    br label [[__OCML_SIN_F64_EXIT]]
+; CHECK:       __ocml_sin_f64.exit:
+; CHECK-NEXT:    [[DOTPN5_I_I:%.*]] = phi double [ [[TMP19]], [[TMP2]] ], [ [[TMP97]], [[TMP21]] ]
+; CHECK-NEXT:    [[DOTPN3_I_I:%.*]] = phi double [ [[TMP17]], [[TMP2]] ], [ [[TMP95]], [[TMP21]] ]
+; CHECK-NEXT:    [[DOTPN1_IN_I_I:%.*]] = phi i32 [ [[TMP20]], [[TMP2]] ], [ [[TMP84]], [[TMP21]] ]
+; CHECK-NEXT:    [[TMP98:%.*]] = fmul double [[DOTPN3_I_I]], [[DOTPN3_I_I]]
+; CHECK-NEXT:    [[TMP99:%.*]] = fmul double [[TMP98]], 5.000000e-01
+; CHECK-NEXT:    [[TMP100:%.*]] = fsub double 1.000000e+00, [[TMP99]]
+; CHECK-NEXT:    [[TMP101:%.*]] = fsub double 1.000000e+00, [[TMP100]]
+; CHECK-NEXT:    [[TMP102:%.*]] = fsub double [[TMP101]], [[TMP99]]
+; CHECK-NEXT:    [[TMP103:%.*]] = fmul double [[TMP98]], [[TMP98]]
+; CHECK-NEXT:    [[TMP104:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double noundef 0xBDA907DB46CC5E42, double noundef 0x3E21EEB69037AB78)
+; CHECK-NEXT:    [[TMP105:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP104]], double noundef 0xBE927E4FA17F65F6)
+; CHECK-NEXT:    [[TMP106:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP105]], double noundef 0x3EFA01A019F4EC90)
+; CHECK-NEXT:    [[TMP107:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP106]], double noundef 0xBF56C16C16C16967)
+; CHECK-NEXT:    [[TMP108:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP107]], double noundef 0x3FA5555555555555)
+; CHECK-NEXT:    [[TMP109:%.*]] = fneg double [[DOTPN5_I_I]]
+; CHECK-NEXT:    [[TMP110:%.*]] = tail call double @llvm.fma.f64(double [[DOTPN3_I_I]], double [[TMP109]], double [[TMP102]])
+; CHECK-NEXT:    [[TMP111:%.*]] = tail call double @llvm.fma.f64(double [[TMP103]], double [[TMP108]], double [[TMP110]])
+; CHECK-NEXT:    [[TMP112:%.*]] = fadd double [[TMP100]], [[TMP111]]
+; CHECK-NEXT:    [[TMP113:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double noundef 0x3DE5E0B2F9A43BB8, double noundef 0xBE5AE600B42FDFA7)
+; CHECK-NEXT:    [[TMP114:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP113]], double noundef 0x3EC71DE3796CDE01)
+; CHECK-NEXT:    [[TMP115:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP114]], double noundef 0xBF2A01A019E83E5C)
+; CHECK-NEXT:    [[TMP116:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP115]], double noundef 0x3F81111111110BB3)
+; CHECK-NEXT:    [[TMP117:%.*]] = fneg double [[TMP98]]
+; CHECK-NEXT:    [[TMP118:%.*]] = fmul double [[DOTPN3_I_I]], [[TMP117]]
+; CHECK-NEXT:    [[TMP119:%.*]] = fmul double [[DOTPN5_I_I]], 5.000000e-01
+; CHECK-NEXT:    [[TMP120:%.*]] = tail call double @llvm.fma.f64(double [[TMP118]], double [[TMP116]], double [[TMP119]])
+; CHECK-NEXT:    [[TMP121:%.*]] = tail call double @llvm.fma.f64(double [[TMP98]], double [[TMP120]], double [[TMP109]])
+; CHECK-NEXT:    [[TMP122:%.*]] = tail call double @llvm.fma.f64(double [[TMP118]], double noundef 0xBFC5555555555555, double [[TMP121]])
+; CHECK-NEXT:    [[TMP123:%.*]] = fsub double [[DOTPN3_I_I]], [[TMP122]]
+; CHECK-NEXT:    [[TMP124:%.*]] = and i32 [[DOTPN1_IN_I_I]], 1
+; CHECK-NEXT:    [[TMP125:%.*]] = icmp eq i32 [[TMP124]], 0
+; CHECK-NEXT:    [[TMP126:%.*]] = select i1 [[TMP125]], double [[TMP123]], double [[TMP112]]
+; CHECK-NEXT:    [[TMP127:%.*]] = bitcast double [[TMP126]] to <2 x i32>
+; CHECK-NEXT:    [[DOTPN1_I_I:%.*]] = shl i32 [[DOTPN1_IN_I_I]], 30
+; CHECK-NEXT:    [[TMP128:%.*]] = bitcast double [[__X]] to <2 x i32>
+; CHECK-NEXT:    [[TMP129:%.*]] = extractelement <2 x i32> [[TMP128]], i64 1
+; CHECK-NEXT:    [[TMP130:%.*]] = xor i32 [[DOTPN1_I_I]], [[TMP129]]
+; CHECK-NEXT:    [[TMP131:%.*]] = and i32 [[TMP130]], -2147483648
+; CHECK-NEXT:    [[TMP132:%.*]] = extractelement <2 x i32> [[TMP127]], i64 1
+; CHECK-NEXT:    [[TMP133:%.*]] = xor i32 [[TMP132]], [[TMP131]]
+; CHECK-NEXT:    [[TMP134:%.*]] = insertelement <2 x i32> [[TMP127]], i32 [[TMP133]], i64 1
+; CHECK-NEXT:    [[TMP135:%.*]] = fcmp one double [[TMP0]], 0x7FF0000000000000
+; CHECK-NEXT:    [[TMP136:%.*]] = select i1 [[TMP135]], <2 x i32> [[TMP134]], <2 x i32> <i32 0, i32 2146959360>
+; CHECK-NEXT:    [[TMP137:%.*]] = bitcast <2 x i32> [[TMP136]] to double
+; CHECK-NEXT:    ret double [[TMP137]]
+;
+entry:
+  %0 = tail call double @llvm.fabs.f64(double %__x)
+  %1 = fcmp olt double %0, 0x41D0000000000000
+  br i1 %1, label %2, label %21
+
+2:                                                ; preds = %entry
+  %3 = fmul double %0, 0x3FE45F306DC9C883
----------------
arsenm wrote:

Use named values, and presumably this can be reduced a lot? 

https://github.com/llvm/llvm-project/pull/91030


More information about the llvm-commits mailing list