[PATCH] D115726: [InstCombine] Fold for masked gather when loading the same value each time.

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 7 06:34:34 PST 2022


sdesmalen added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/masked_intrinsics.ll:297
+  %broadcast.splat = shufflevector <2 x i64*> %broadcast.splatinsert, <2 x i64*> poison, <2 x i32> zeroinitializer
+  %res = call <2 x i64> @llvm.masked.gather.v2i64(<2 x i64*> %broadcast.splat, i32 8, <2 x i1> <i1 1, i1 1>, <2 x i64> undef)
+  ret <2 x i64> %res
----------------
CarolineConcatto wrote:
> sdesmalen wrote:
> > just write: `<2 x i64*> <i64* %src, i64* %src>`
> I believe this does not work, because src needs to be a constant.
> I need to use gep and inserts in each position of the vector. That is the same as doing a splat
You're right, I didn't realise that this notation doesn't work for constants!


================
Comment at: llvm/test/Transforms/InstCombine/masked_intrinsics.ll:328
+
+;; Splat Value and all inactive mask
+define <2 x i64> @gather_v2i64_uniform_ptrs_all_inactive_mask(i64* %src) {
----------------
CarolineConcatto wrote:
> sdesmalen wrote:
> > I think you can remove this test, because it's unaffected by your patch.
> That is not true. I added these lines:
>   auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(2));
>   if (!ConstMask)
>     return nullptr;
Returning `nullptr` means that InstCombine is not combining this case, i.e. that your combine function makes no changes.
You can see that in `InstCombinerImpl::run` where it calls the `visit` function.

In `negative_gather_v2i64_uniform_ptrs_all_inactive_mask` you're testing that the code is optimized away entirely if the mask is all-zero, but that's not caused by your code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115726



More information about the llvm-commits mailing list