From: Matt Arsenault Date: Thu, 18 May 2023 13:39:32 +0000 (+0100) Subject: ValueTracking: Check context instruction is in a function X-Git-Tag: upstream/17.0.6~8014 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4130ccc8be9567bfd8673b2ab1bdcd4f1463af89;p=platform%2Fupstream%2Fllvm.git ValueTracking: Check context instruction is in a function --- diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index bbd7a24..6a008c2 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -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()) diff --git a/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll b/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll index 06d08e1..7573296 100644 --- a/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll +++ b/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll @@ -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) }