[PATCH] D151060: [Clang][Sema] Generate vector vs scalar builtin overloads

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 12:02:49 PDT 2023


aaron.ballman added inline comments.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:9041-9044
+      // (allowing splatting the scalar to a vector).
+      for (unsigned Candidate = 0; Candidate < 2; ++Candidate) {
+        for (QualType Vec1Ty : CandidateTypes[Candidate].vector_types()) {
+          for (QualType Vec2Ty : CandidateTypes[Candidate].vector_types()) {
----------------
porglezomp wrote:
> aaron.ballman wrote:
> > I'm a bit confused -- the comment says this is to allow splatting the scalar to a vector, but... what is the scalar type in these loops?
> Right, so my goal here is to generate the two vector-operand overload candidates so that overload resolution can pick one of those and then apply the implicit scalar->vector conversion with the splat. I //think// this is the correct approach (it's based on how the compound assignment operators already handle this) but I need to improve my comments here.
> 
> Also, how do we like the loop here for trying both sides, as opposed to duplicating the code? This is really acting as an `if left operand / else if right operand` to avoid duplicating the code but I was worried writing it that the loop obscures the intent. Maybe that's also just "make the comment better" or maybe that part is clear enough.
> Right, so my goal here is to generate the two vector-operand overload candidates so that overload resolution can pick one of those and then apply the implicit scalar->vector conversion with the splat. I think this is the correct approach (it's based on how the compound assignment operators already handle this) but I need to improve my comments here.

Huh... that code looks equally as suspicious to me as well (for the same reason, it's looping over the same vector types twice). @fhahn authored that code, so perhaps he can educate me on what I'm missing.

> Also, how do we like the loop here for trying both sides, as opposed to duplicating the code? This is really acting as an if left operand / else if right operand to avoid duplicating the code but I was worried writing it that the loop obscures the intent. Maybe that's also just "make the comment better" or maybe that part is clear enough.

It too me a hot minute to figure out what the code was doing, but once I picked up on this being a way to avoid code duplication, I was happy enough with it. It might be slightly more clear to refactor to use a lambda for the actual logic and then you can do if left operand/else without duplication.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151060



More information about the cfe-commits mailing list