[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;
+    }
+  }
+
+  void dropPoisonGeneratingFlags() {
+    switch (getOpcode()) {
----------------
arsenm wrote:

You can just drop all the flags that could emit poison at once. All the flags are in the same bitfield in the MachineInstr unlike in the IR 

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


More information about the llvm-commits mailing list