[PATCH] D156238: [InstCombine] Generalize foldICmpWithMinMax

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 24 09:54:58 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:4947
+  return false;
+}
+Instruction *InstCombinerImpl::foldICmpWithMinMaxImpl(
----------------
See: `m_c_MaxOrMin` in PatternMatch. This can be:
```
if(!match(Val, m_c_MaxOrMin(X, Y)))
return false;
MinMaxIntrinsic = cast<Intrinsic>(Val)->getIntrinsicID();
return true;
```


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:4948
+}
+Instruction *InstCombinerImpl::foldICmpWithMinMaxImpl(
+    Instruction &I, Value *X, Value *Y, Value *Z, Intrinsic::ID MinMaxIntrinsic,
----------------
This needs a header comment to explain its purpose.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:4958
+  SimplifyQuery Q = SQ.getWithInstruction(&I);
+  auto AsOptional = [](Value *Val) -> std::optional<bool> {
+    if (!Val)
----------------
`AsOptional` doens't seem like a very useful name. Maybe `IsCondKnownTrue` or something might be better.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:4982
+    //    X != Z      X <= Y || Y != Z X >= Y || Y != Z // nofold
+    //    X == Z          X > Y           X < Y
+
----------------
Two things about these comments.

1) They should reference the predicate they are folding for. I.e it looks like the top comment is regarding `icmp eq` and the bottom one is regarding `icmp ne` but thats not clear anywhere.

2) Can they be a bit more explicit that the second/third columns are the resulting fold (i.e add table column names).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156238/new/

https://reviews.llvm.org/D156238



More information about the llvm-commits mailing list