[llvm] 45dca04 - Exclude bitcast and ext/trunc signbit optimization on ppc_fp128
Eric Christopher via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 10 17:20:23 PDT 2020
Author: Eric Christopher
Date: 2020-04-10T17:07:55-07:00
New Revision: 45dca043957a43cd07715da40690a80504d37de0
URL: https://github.com/llvm/llvm-project/commit/45dca043957a43cd07715da40690a80504d37de0
DIFF: https://github.com/llvm/llvm-project/commit/45dca043957a43cd07715da40690a80504d37de0.diff
LOG: Exclude bitcast and ext/trunc signbit optimization on ppc_fp128
Revision a1c05fe <https://reviews.llvm.org/rGa1c05fe20f3def1f1be9f50d2adefc6b6f1578ad>
removed bitcast from the list of problematic transformations, however:
%97 = fptrunc ppc_fp128 %2 to double // we need to check ppc_fp128 here to prevent the transformation
%98 = bitcast double %97 to i64 // a1c05fe checks ppc_fp128 at here
%99 = icmp slt i64 %98, 0
%100 = zext i1 %99 to i8
store i8 %100, i8* %7, align 1
so this patch does that. I'm also disabling it in the presence of extend just in case.
I verified separately that the hash of -std::infinity and std::infinity don't match now.
Differential Revision: https://reviews.llvm.org/D77911
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 8f6cd2a76b45..37ed6a0e3888 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2768,23 +2768,28 @@ static Instruction *foldICmpBitCast(ICmpInst &Cmp,
// The sign-bit is always the most significant bit in those types.
const APInt *C;
bool TrueIfSigned;
- if (!BCSrcOp->getType()->isPPC_FP128Ty() && match(Op1, m_APInt(C)) &&
- Bitcast->hasOneUse() && isSignBitCheck(Pred, *C, TrueIfSigned)) {
+ if (match(Op1, m_APInt(C)) && Bitcast->hasOneUse() &&
+ isSignBitCheck(Pred, *C, TrueIfSigned)) {
if (match(BCSrcOp, m_FPExt(m_Value(X))) ||
match(BCSrcOp, m_FPTrunc(m_Value(X)))) {
// (bitcast (fpext/fptrunc X)) to iX) < 0 --> (bitcast X to iY) < 0
// (bitcast (fpext/fptrunc X)) to iX) > -1 --> (bitcast X to iY) > -1
Type *XType = X->getType();
- Type *NewType = Builder.getIntNTy(XType->getScalarSizeInBits());
- if (auto *XVTy = dyn_cast<VectorType>(XType))
- NewType = VectorType::get(NewType, XVTy->getNumElements());
- Value *NewBitcast = Builder.CreateBitCast(X, NewType);
- if (TrueIfSigned)
- return new ICmpInst(ICmpInst::ICMP_SLT, NewBitcast,
- ConstantInt::getNullValue(NewType));
- else
- return new ICmpInst(ICmpInst::ICMP_SGT, NewBitcast,
- ConstantInt::getAllOnesValue(NewType));
+
+ // We can't currently handle Power style floating point operations here.
+ if (!(XType->isPPC_FP128Ty() || BCSrcOp->getType()->isPPC_FP128Ty())) {
+
+ Type *NewType = Builder.getIntNTy(XType->getScalarSizeInBits());
+ if (auto *XVTy = dyn_cast<VectorType>(XType))
+ NewType = VectorType::get(NewType, XVTy->getNumElements());
+ Value *NewBitcast = Builder.CreateBitCast(X, NewType);
+ if (TrueIfSigned)
+ return new ICmpInst(ICmpInst::ICMP_SLT, NewBitcast,
+ ConstantInt::getNullValue(NewType));
+ else
+ return new ICmpInst(ICmpInst::ICMP_SGT, NewBitcast,
+ ConstantInt::getAllOnesValue(NewType));
+ }
}
}
}
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 96673eb9e451..4786c67375f6 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -3713,8 +3713,9 @@ define i1 @signbit_bitcast_fpext_ppc_fp128(float %x) {
define i1 @signbit_bitcast_fptrunc_ppc_fp128(ppc_fp128 %x) {
; CHECK-LABEL: @signbit_bitcast_fptrunc_ppc_fp128(
-; CHECK-NEXT: [[TMP1:%.*]] = bitcast ppc_fp128 [[X:%.*]] to i128
-; CHECK-NEXT: [[S4:%.*]] = icmp slt i128 [[TMP1]], 0
+; CHECK-NEXT: [[S2:%.*]] = fptrunc ppc_fp128 [[X:%.*]] to float
+; CHECK-NEXT: [[S3:%.*]] = bitcast float [[S2]] to i32
+; CHECK-NEXT: [[S4:%.*]] = icmp slt i32 [[S3]], 0
; CHECK-NEXT: ret i1 [[S4]]
;
%s2 = fptrunc ppc_fp128 %x to float
More information about the llvm-commits
mailing list