[PATCH] D77911: Exclude bitcast and ext/trunc signbit optimization on ppc_fp128

Eric Christopher via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 15:37:23 PDT 2020


echristo created this revision.
echristo added reviewers: Carrot, spatel.
Herald added subscribers: llvm-commits, hiraditya, mcrosier.
Herald added a project: LLVM.
echristo retitled this revision from "Exclude bitcast and ext/trunc on ppc_fp128 " to "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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77911

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Transforms/InstCombine/icmp.ll


Index: llvm/test/Transforms/InstCombine/icmp.ll
===================================================================
--- llvm/test/Transforms/InstCombine/icmp.ll
+++ llvm/test/Transforms/InstCombine/icmp.ll
@@ -3713,8 +3713,9 @@
 
 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
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2768,23 +2768,28 @@
     // 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));
+        }
       }
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77911.256683.patch
Type: text/x-patch
Size: 3031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200410/0ca6cc22/attachment.bin>


More information about the llvm-commits mailing list