[llvm] [InstCombine] Preserve IR flags when reordering icmp/fcmp/cast through a shuffle (PR #208627)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 12 22:45:37 PDT 2026


================
@@ -2007,14 +2007,22 @@ static Value *buildNew(Instruction *I, ArrayRef<Value*> NewOps,
       }
       return New;
     }
-    case Instruction::ICmp:
+    case Instruction::ICmp: {
       assert(NewOps.size() == 2 && "icmp with #ops != 2");
-      return Builder.CreateICmp(cast<ICmpInst>(I)->getPredicate(), NewOps[0],
-                                NewOps[1]);
-    case Instruction::FCmp:
+      Value *New = Builder.CreateICmp(cast<ICmpInst>(I)->getPredicate(),
+                                      NewOps[0], NewOps[1]);
+      if (auto *NewI = dyn_cast<Instruction>(New))
+        NewI->copyIRFlags(I);
+      return New;
+    }
+    case Instruction::FCmp: {
       assert(NewOps.size() == 2 && "fcmp with #ops != 2");
-      return Builder.CreateFCmp(cast<FCmpInst>(I)->getPredicate(), NewOps[0],
-                                NewOps[1]);
+      Value *New = Builder.CreateFCmp(cast<FCmpInst>(I)->getPredicate(),
----------------
ayrai-gb wrote:

updated to use `CreateFCmpFMF`. thanks!

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


More information about the llvm-commits mailing list