[llvm] 9dcd719 - [InstCombine] avoid crashing in pow->ldexp
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 10 05:04:15 PST 2023
Author: Sanjay Patel
Date: 2023-02-10T08:03:13-05:00
New Revision: 9dcd7195a21c65d51b703f4b270e62461d18cd69
URL: https://github.com/llvm/llvm-project/commit/9dcd7195a21c65d51b703f4b270e62461d18cd69
DIFF: https://github.com/llvm/llvm-project/commit/9dcd7195a21c65d51b703f4b270e62461d18cd69.diff
LOG: [InstCombine] avoid crashing in pow->ldexp
Similar to 62a0a1b9eea7788c1f9dbae -
We have pow math intrinsics in IR, but no ldexp intrinsics
to handle vector types.
A patch for that was proposed in D14327, but it was not completed.
Issue #60605
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/pow_fp_int.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index d497a9e8f9f0..53fe3dfb1313 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1939,7 +1939,8 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilderBase &B) {
AttributeList NoAttrs; // Attributes are only meaningful on the original call
// pow(2.0, itofp(x)) -> ldexp(1.0, x)
- if (match(Base, m_SpecificFP(2.0)) &&
+ // TODO: This does not work for vectors because there is no ldexp intrinsic.
+ if (!Ty->isVectorTy() && match(Base, m_SpecificFP(2.0)) &&
(isa<SIToFPInst>(Expo) || isa<UIToFPInst>(Expo)) &&
hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)) {
if (Value *ExpoI = getIntToFPVal(Expo, B, TLI->getIntSize()))
diff --git a/llvm/test/Transforms/InstCombine/pow_fp_int.ll b/llvm/test/Transforms/InstCombine/pow_fp_int.ll
index d4d27c2e0201..8718df3e8663 100644
--- a/llvm/test/Transforms/InstCombine/pow_fp_int.ll
+++ b/llvm/test/Transforms/InstCombine/pow_fp_int.ll
@@ -484,5 +484,19 @@ define double @powf_exp_const2_int_no_fast(double %base) {
ret double %res
}
+; TODO: This could be transformed the same as scalar if there is an ldexp intrinsic.
+
+define <2 x float> @pow_sitofp_const_base_2_no_fast_vector(<2 x i8> %x) {
+; CHECK-LABEL: @pow_sitofp_const_base_2_no_fast_vector(
+; CHECK-NEXT: [[S:%.*]] = sitofp <2 x i8> [[X:%.*]] to <2 x float>
+; CHECK-NEXT: [[EXP2:%.*]] = call <2 x float> @llvm.exp2.v2f32(<2 x float> [[S]])
+; CHECK-NEXT: ret <2 x float> [[EXP2]]
+;
+ %s = sitofp <2 x i8> %x to <2 x float>
+ %r = call <2 x float> @llvm.pow.v2f32(<2 x float><float 2.0, float 2.0>, <2 x float> %s)
+ ret <2 x float> %r
+}
+
declare float @llvm.pow.f32(float, float)
declare double @llvm.pow.f64(double, double)
+declare <2 x float> @llvm.pow.v2f32(<2 x float>, <2 x float>)
More information about the llvm-commits
mailing list