[llvm] [InstCombine] Fold `icmp eq/ne min|max(X, Y), Z` (PR #67087)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 06:13:21 PDT 2023


================
@@ -5022,6 +5022,12 @@ InstCombinerImpl::foldICmpWithMinMaxImpl(Instruction &I,
     std::swap(CmpXZ, CmpYZ);
   }
 
+  auto FoldIntoCmpYZ = [&]() -> Instruction * {
+    if (CmpYZ.has_value())
+      return replaceInstUsesWith(I, ConstantInt::getBool(I.getType(), *CmpYZ));
+    return ICmpInst::Create(Instruction::ICmp, Pred, Y, Z);
+  };
----------------
dtcxzyw wrote:

It is also used in
https://github.com/llvm/llvm-project/blob/07151f0241d3f893cb36eb2dbc395d4098f74a87/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L5079
and
https://github.com/llvm/llvm-project/blob/07151f0241d3f893cb36eb2dbc395d4098f74a87/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L5088


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


More information about the llvm-commits mailing list