[llvm] 68805de - [IVDesc] Reuse getBinOpIdentity in getRecurrenceIdentity [nfc]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 09:10:55 PDT 2024


Author: Philip Reames
Date: 2024-08-30T09:10:34-07:00
New Revision: 68805de90280dc8d8df39ff3f6289033deb487cf

URL: https://github.com/llvm/llvm-project/commit/68805de90280dc8d8df39ff3f6289033deb487cf
DIFF: https://github.com/llvm/llvm-project/commit/68805de90280dc8d8df39ff3f6289033deb487cf.diff

LOG: [IVDesc] Reuse getBinOpIdentity in getRecurrenceIdentity [nfc]

Avoid duplication so that we can easily tell these lists are in sync.

Added: 
    

Modified: 
    llvm/lib/Analysis/IVDescriptors.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index f5258601fd5d49..ba3619417114c7 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -1040,28 +1040,13 @@ Value *RecurrenceDescriptor::getRecurrenceIdentity(RecurKind K, Type *Tp,
   case RecurKind::Xor:
   case RecurKind::Add:
   case RecurKind::Or:
-    // Adding, Xoring, Oring zero to a number does not change it.
-    return ConstantInt::get(Tp, 0);
   case RecurKind::Mul:
-    // Multiplying a number by 1 does not change it.
-    return ConstantInt::get(Tp, 1);
   case RecurKind::And:
-    // AND-ing a number with an all-1 value does not change it.
-    return ConstantInt::get(Tp, -1, true);
   case RecurKind::FMul:
-    // Multiplying a number by 1 does not change it.
-    return ConstantFP::get(Tp, 1.0L);
-  case RecurKind::FMulAdd:
   case RecurKind::FAdd:
-    // Adding zero to a number does not change it.
-    // FIXME: Ideally we should not need to check FMF for FAdd and should always
-    // use -0.0. However, this will currently result in mixed vectors of 0.0/-0.0.
-    // Instead, we should ensure that 1) the FMF from FAdd are propagated to the PHI
-    // nodes where possible, and 2) PHIs with the nsz flag + -0.0 use 0.0. This would
-    // mean we can then remove the check for noSignedZeros() below (see D98963).
-    if (FMF.noSignedZeros())
-      return ConstantFP::get(Tp, 0.0L);
-    return ConstantFP::get(Tp, -0.0L);
+    return ConstantExpr::getBinOpIdentity(getOpcode(K), Tp, false, FMF.noSignedZeros());
+  case RecurKind::FMulAdd:
+    return ConstantExpr::getBinOpIdentity(Instruction::FAdd, Tp, false, FMF.noSignedZeros());
   case RecurKind::UMin:
     return ConstantInt::get(Tp, -1, true);
   case RecurKind::UMax:


        


More information about the llvm-commits mailing list