[llvm] [GISel][CombinerHelper] Push freeze through non-poison-producing operands (PR #90618)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri May 3 02:41:52 PDT 2024


================
@@ -34,6 +34,83 @@ class GenericMachineInstr : public MachineInstr {
   static bool classof(const MachineInstr *MI) {
     return isPreISelGenericOpcode(MI->getOpcode());
   }
+
+  bool hasPoisonGeneratingFlags() const {
+    switch (getOpcode()) {
+    case TargetOpcode::G_ADD:
+    case TargetOpcode::G_SUB:
+    case TargetOpcode::G_MUL:
+    case TargetOpcode::G_SHL:
+    case TargetOpcode::G_TRUNC:
+      return getFlag(NoUWrap) || getFlag(NoSWrap);
+
+    case TargetOpcode::G_UDIV:
+    case TargetOpcode::G_SDIV:
+    case TargetOpcode::G_ASHR:
+    case TargetOpcode::G_LSHR:
+      return getFlag(IsExact);
+
+    case TargetOpcode::G_OR:
+      return getFlag(Disjoint);
+
+    case TargetOpcode::G_UITOFP:
+    case TargetOpcode::G_ZEXT:
+      return getFlag(NonNeg);
+
+    case TargetOpcode::G_FNEG:
+    case TargetOpcode::G_FADD:
+    case TargetOpcode::G_FSUB:
+    case TargetOpcode::G_FMUL:
+    case TargetOpcode::G_FDIV:
+    case TargetOpcode::G_FREM:
+    case TargetOpcode::G_FCMP:
+      return getFlag(FmNoNans) || getFlag(FmNoInfs);
+
+    default:
+      return false;
----------------
arsenm wrote:

This should return the conservative default of true (or maybe just test if any flags are set at all). I'm also not sure we need to consider the opcodes. From construction, we won't have other flags on the MachineInstr

https://github.com/llvm/llvm-project/pull/90618


More information about the llvm-commits mailing list