================
@@ -2633,28 +2633,43 @@ Value *LibCallSimplifier::optimizeExp2(CallInst *CI,
IRBuilderBase &B) {
// exp2(sitofp(x)) -> ldexp(1.0, sext(x)) if sizeof(x) <= IntSize
// exp2(uitofp(x)) -> ldexp(1.0, zext(x)) if sizeof(x) < IntSize
+ // exp2(uitofp(x)) -> ldexp(1.0, umin(x, C)) if sizeof(x) == IntSize
Value *Op = CI->getArgOperand(0);
- if ((isa<SIToFPInst>(Op) || isa<UIToFPInst>(Op)) &&
- (UseIntrinsic ||
- hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)))
{
- if (Value *Exp = getIntToFPVal(Op, B, TLI->getIntSize())) {
- Constant *One = ConstantFP::get(Ty, 1.0);
+ if (!isa<SIToFPInst, UIToFPInst>(Op) ||
+ (!UseIntrinsic &&
+ !hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)))
+ return Ret;
- if (UseIntrinsic) {
- return copyFlags(*CI, B.CreateIntrinsic(Intrinsic::ldexp,
- {Ty, Exp->getType()},
- {One, Exp}, CI));
- }
+ unsigned IntSize = TLI->getIntSize();
+ Value *Exp = getIntToFPVal(Op, B, IntSize);
+ Value *UIntOp = nullptr;
+ // A uitofp source as wide as int may exceed INT_MAX, so clamp it for ldexp.
+ if (!Exp && UseIntrinsic && match(Op, m_UIToFP(m_Value(UIntOp))) &&
+ UIntOp->getType()->getScalarSizeInBits() == IntSize) {
----------------
harrisonGPU wrote:
Thanks, I have updated and added new tests.
https://github.com/llvm/llvm-project/pull/227380
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits