[PATCH] D159326: [InstCombine] Add support for simplifying inverted `select` in `foldAndOrOfSelectUsingImpliedCond`; NFC

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 31 18:29:05 PDT 2023


goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, RKSimon.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

No change to any functionality at the moment, this is preperatory for
a `foldSelectOfBools` refactor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159326

Files:
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  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
@@ -2643,9 +2643,8 @@
   return nullptr;
 }
 
-Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond(Value *Op,
-                                                                 SelectInst &SI,
-                                                                 bool IsAnd) {
+Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond(
+    Value *Op, SelectInst &SI, bool IsAnd, bool NotSICond) {
   Value *CondVal = SI.getCondition();
   Value *A = SI.getTrueValue();
   Value *B = SI.getFalseValue();
@@ -2657,6 +2656,9 @@
   if (!Res)
     return nullptr;
 
+  if (NotSICond)
+    *Res = !*Res;
+
   Value *Zero = Constant::getNullValue(A->getType());
   Value *One = Constant::getAllOnesValue(A->getType());
 
Index: llvm/lib/Transforms/InstCombine/InstCombineInternal.h
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -390,7 +390,8 @@
   //   or i1 Op, SI  / select i1 Op, i1 true, i1 SI  (if IsAnd = false)
   // into simplier select instruction using isImpliedCondition.
   Instruction *foldAndOrOfSelectUsingImpliedCond(Value *Op, SelectInst &SI,
-                                                 bool IsAnd);
+                                                 bool IsAnd,
+                                                 bool NotSICond = false);
 
   Instruction *hoistFNegAboveFMulFDiv(Value *FNegOp, Instruction &FMFSource);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159326.555222.patch
Type: text/x-patch
Size: 1739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230901/9a60b373/attachment.bin>


More information about the llvm-commits mailing list