[PATCH] D147146: [InstCombine] Should postpone zero check folding if the compare argument is a call

Alexander via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 29 06:23:24 PDT 2023


alex-t created this revision.
alex-t added reviewers: nikic, clubby789.
Herald added subscribers: kosarev, StephenFan, hiraditya, tpr.
Herald added a project: All.
alex-t requested review of this revision.
Herald added a project: LLVM.

https://reviews.llvm.org/D140798 introduces a regression in AMDGPU backend.
In case zero check is folded to llvm.usub.sat before inline, it covers opportunities for other inst-combines that may have higher precedence.
As a result, we get suboptimal code.


https://reviews.llvm.org/D147146

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -834,7 +834,8 @@
   // ugt 0 is canonicalized to ne 0 and requires special handling
   // (a != 0) ? a + -1 : 0 -> usub.sat(a, 1)
   if (Pred == ICmpInst::ICMP_NE) {
-    if (match(B, m_Zero()) && match(TrueVal, m_Add(m_Specific(A), m_AllOnes())))
+    if (!isa<CallInst>(A) && match(B, m_Zero()) &&
+        match(TrueVal, m_Add(m_Specific(A), m_AllOnes())))
       return Builder.CreateBinaryIntrinsic(Intrinsic::usub_sat, A,
                                            ConstantInt::get(A->getType(), 1));
     return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147146.509332.patch
Type: text/x-patch
Size: 777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230329/9d7ccdb1/attachment.bin>


More information about the llvm-commits mailing list