[PATCH] D94934: [llvm] Prevent infinite loop in InstCombine of select statements

Theodore Popp via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 18 14:41:34 PST 2021


tpopp created this revision.
Herald added a subscriber: hiraditya.
tpopp requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This fixes an issue where the RHS and LHS the comparison operation
creating the predicate were swapped back and forth forever.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94934

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
@@ -1123,7 +1123,10 @@
     // else. Only do this if CmpRHS is a constant, as profitability is not
     // clear for other cases.
     // FIXME: The replacement could be performed recursively.
-    if (isa<Constant>(CmpRHS) && !isa<ConstantExpr>(CmpRHS))
+    auto IsConstant = [](auto *V) {
+      return isa<Constant>(V) && !isa<ConstantExpr>(V);
+    };
+    if (IsConstant(CmpRHS) && !IsConstant(CmpLHS))
       if (auto *I = dyn_cast<Instruction>(TrueVal))
         if (I->hasOneUse())
           for (Use &U : I->operands())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94934.317422.patch
Type: text/x-patch
Size: 776 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210118/b6ee0429/attachment.bin>


More information about the llvm-commits mailing list