diff options
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 7 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/exp2-1.ll | 29 |
2 files changed, 35 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 60b417d..d497a9e 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -2217,11 +2217,16 @@ Value *LibCallSimplifier::optimizeExp2(CallInst *CI, IRBuilderBase &B) { hasFloatVersion(M, Name)) Ret = optimizeUnaryDoubleFP(CI, B, TLI, true); + // Bail out for vectors because the code below only expects scalars. + // TODO: This could be allowed if we had a ldexp intrinsic (D14327). Type *Ty = CI->getType(); - Value *Op = CI->getArgOperand(0); + if (Ty->isVectorTy()) + return Ret; // exp2(sitofp(x)) -> ldexp(1.0, sext(x)) if sizeof(x) <= IntSize // exp2(uitofp(x)) -> ldexp(1.0, zext(x)) if sizeof(x) < IntSize + // TODO: This does not propagate FMF. + Value *Op = CI->getArgOperand(0); if ((isa<SIToFPInst>(Op) || isa<UIToFPInst>(Op)) && hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)) { if (Value *Exp = getIntToFPVal(Op, B, TLI->getIntSize())) diff --git a/llvm/test/Transforms/InstCombine/exp2-1.ll b/llvm/test/Transforms/InstCombine/exp2-1.ll index 471f036a..92a06ee 100644 --- a/llvm/test/Transforms/InstCombine/exp2-1.ll +++ b/llvm/test/Transforms/InstCombine/exp2-1.ll @@ -302,3 +302,32 @@ define float @sitofp_scalar_intrinsic_with_FMF(i8 %x) { %r = call nnan float @llvm.exp2.f32(float %s) ret float %r } + +; PR60605 +; This would crash because there is no ldexp intrinsic. + +define <2 x float> @sitofp_vector_intrinsic_with_FMF(<2 x i8> %x) { +; LDEXP32-LABEL: @sitofp_vector_intrinsic_with_FMF( +; LDEXP32-NEXT: [[S:%.*]] = sitofp <2 x i8> [[X:%.*]] to <2 x float> +; LDEXP32-NEXT: [[R:%.*]] = call nnan <2 x float> @llvm.exp2.v2f32(<2 x float> [[S]]) +; LDEXP32-NEXT: ret <2 x float> [[R]] +; +; LDEXP16-LABEL: @sitofp_vector_intrinsic_with_FMF( +; LDEXP16-NEXT: [[S:%.*]] = sitofp <2 x i8> [[X:%.*]] to <2 x float> +; LDEXP16-NEXT: [[R:%.*]] = call nnan <2 x float> @llvm.exp2.v2f32(<2 x float> [[S]]) +; LDEXP16-NEXT: ret <2 x float> [[R]] +; +; NOLDEXPF-LABEL: @sitofp_vector_intrinsic_with_FMF( +; NOLDEXPF-NEXT: [[S:%.*]] = sitofp <2 x i8> [[X:%.*]] to <2 x float> +; NOLDEXPF-NEXT: [[R:%.*]] = call nnan <2 x float> @llvm.exp2.v2f32(<2 x float> [[S]]) +; NOLDEXPF-NEXT: ret <2 x float> [[R]] +; +; NOLDEXP-LABEL: @sitofp_vector_intrinsic_with_FMF( +; NOLDEXP-NEXT: [[S:%.*]] = sitofp <2 x i8> [[X:%.*]] to <2 x float> +; NOLDEXP-NEXT: [[R:%.*]] = call nnan <2 x float> @llvm.exp2.v2f32(<2 x float> [[S]]) +; NOLDEXP-NEXT: ret <2 x float> [[R]] +; + %s = sitofp <2 x i8> %x to <2 x float> + %r = call nnan <2 x float> @llvm.exp2.v2f32(<2 x float> %s) + ret <2 x float> %r +} |