ValueTracking: Check context instruction is in a function
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Thu, 18 May 2023 13:39:32 +0000 (14:39 +0100)
committerMatt Arsenault <arsenm2@gmail.com>
Thu, 18 May 2023 13:40:13 +0000 (14:40 +0100)
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll

index bbd7a24..6a008c2 100644 (file)
@@ -4620,6 +4620,9 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
         if ((Known.KnownFPClasses & fcZero) != fcNone &&
             !Known.isKnownNeverSubnormal()) {
           const Function *Parent = II->getFunction();
+          if (!Parent)
+            break;
+
           DenormalMode Mode = Parent->getDenormalMode(
               II->getType()->getScalarType()->getFltSemantics());
           if (Mode != DenormalMode::getIEEE())
index 06d08e1..7573296 100644 (file)
@@ -138,3 +138,35 @@ define internal i1 @simplify_fcmp_ord_log_callee(double %a) {
 }
 
 declare double @llvm.log.f64(double)
+
+declare float @llvm.maxnum.f32(float, float) #0
+declare <4 x float> @foo() #1
+
+define void @caller_maxnum() {
+; CHECK-LABEL: define void @caller_maxnum() {
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    [[I1_I:%.*]] = call <4 x float> @foo()
+; CHECK-NEXT:    [[I2_I:%.*]] = extractelement <4 x float> [[I1_I]], i64 0
+; CHECK-NEXT:    [[I3_I:%.*]] = fmul float [[I2_I]], 0.000000e+00
+; CHECK-NEXT:    [[I4_I:%.*]] = call float @llvm.maxnum.f32(float [[I3_I]], float 0.000000e+00)
+; CHECK-NEXT:    [[I5_I:%.*]] = call float @llvm.maxnum.f32(float [[I4_I]], float [[I2_I]])
+; CHECK-NEXT:    ret void
+;
+bb:
+  call void @callee_maxnum()
+  ret void
+}
+
+define internal void @callee_maxnum() {
+bb:
+  %i1 = call <4 x float> @foo()
+  %i2 = extractelement <4 x float> %i1, i64 0
+  %i3 = fmul float %i2, 0.000000e+00
+  %i4 = call float @llvm.maxnum.f32(float %i3, float 0.000000e+00)
+  %i5 = call float @llvm.maxnum.f32(float %i4, float %i2)
+  %i6 = fcmp olt float %i5, 0.000000e+00
+  ret void
+}
+
+attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }