Index: llvm/lib/Analysis/ConstantFolding.cpp =================================================================== --- llvm/lib/Analysis/ConstantFolding.cpp +++ llvm/lib/Analysis/ConstantFolding.cpp @@ -1946,8 +1946,12 @@ static Constant *constantFoldCanonicalize(const Type *Ty, const CallBase *CI, const APFloat &Src) { // Zero, positive and negative, is always OK to fold. - if (Src.isZero()) - return ConstantFP::get(CI->getContext(), Src); + if (Src.isZero()) { + // Get a fresh 0, since ppc_fp128 does have non-canonical zeros. + return ConstantFP::get( + CI->getContext(), + APFloat::getZero(Src.getSemantics(), Src.isNegative())); + } if (!Ty->isIEEELikeFPTy()) return nullptr; Index: llvm/test/Transforms/InstSimplify/canonicalize.ll =================================================================== --- llvm/test/Transforms/InstSimplify/canonicalize.ll +++ llvm/test/Transforms/InstSimplify/canonicalize.ll @@ -593,6 +593,30 @@ ret ppc_fp128 %ret } +define ppc_fp128 @canonicalize_noncanonical_zero_0_ppcf128() { +; CHECK-LABEL: @canonicalize_noncanonical_zero_0_ppcf128( +; CHECK-NEXT: ret ppc_fp128 0xM00000000000000000000000000000000 +; + %ret = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM0000000000000000ffffffffffffffff) + ret ppc_fp128 %ret +} + +define ppc_fp128 @canonicalize_noncanonical_zero_1_ppcf128() { +; CHECK-LABEL: @canonicalize_noncanonical_zero_1_ppcf128( +; CHECK-NEXT: ret ppc_fp128 0xM00000000000000000000000000000000 +; + %ret = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM00000000000000000000000000000001) + ret ppc_fp128 %ret +} + +define ppc_fp128 @canonicalize_noncanonical_negzero_0_ppcf128() { +; CHECK-LABEL: @canonicalize_noncanonical_negzero_0_ppcf128( +; CHECK-NEXT: ret ppc_fp128 0xM80000000000000000000000000000000 +; + %ret = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM8000000000000000ffffffffffffffff) + ret ppc_fp128 %ret +} + define ppc_fp128 @canonicalize_inf_ppcf128() { ; CHECK-LABEL: @canonicalize_inf_ppcf128( ; CHECK-NEXT: [[RET:%.*]] = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM7FF00000000000000000000000000000)