Following the discussion in pr32486, adding the simplification:
shuffle %x, %y, undef -> undef
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
4147–4149 ↗ | (On Diff #95955) | microopt: you can move this up to the beginning of the function. |
test/Transforms/InstSimplify/shufflevector.ll | ||
113–119 ↗ | (On Diff #95955) | We have a similar case here, maybe it makes sense to handle them together? |
We are not allowed to fold (select undef x y) -> undef, but we can fold (select undef x y) to x or to y. Likewise, I think this transformation needs to be (shufflevector x y undef) -> x.
Wait, never mind, LangRef says: "If the shuffle mask is undef, the result vector is undef"
test/Transforms/InstSimplify/shufflevector.ll | ||
---|---|---|
113–119 ↗ | (On Diff #95955) | Sorry i don't follow you. What do you mean by handling them together? |
Uhm, I don't follow you. Maybe DAGCombiner has a similar transformation, but instsimplify is powerful enough to handle the case I pointed out.
[davide@cupiditate bin]$ ./opt -instsimplify tinkywinky.ll -S ; ModuleID = 'tinkywinky.ll' source_filename = "tinkywinky.ll" define <4 x i32> @undef_mask(<4 x i32> %x) { ret <4 x i32> undef } [davide@cupiditate bin]$ cat tinkywinky.ll define <4 x i32> @undef_mask(<4 x i32> %x) { %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> undef ret <4 x i32> %shuf }
Sorry, what i really meant was InstructionSimplify.cpp:4154
test/Transforms/InstSimplify/shufflevector.ll | ||
---|---|---|
113–119 ↗ | (On Diff #95955) | I actually meant InstructionSimplify.cpp:4154 :) |
test/Transforms/InstSimplify/shufflevector.ll | ||
---|---|---|
113–119 ↗ | (On Diff #95955) | I was wondering how hard it would be to extend that combine to handle also this case. |
test/Transforms/InstSimplify/shufflevector.ll | ||
---|---|---|
113–119 ↗ | (On Diff #95955) | I plan in a future patch to do a refactoring/NFC-ish canonicalization of the shuffle input vectors and the mask. I believe that will make the special handling of the "single constant vector" case unnecessary, because the unreferenced variable vector will be canonicalized to an undef. Similarly, it is possible that canonicalization will cover the case of an undef mask, because it will replace both vector operands to undefs and then trivial constant-folding will handle that case. |
test/Transforms/InstSimplify/shufflevector.ll | ||
---|---|---|
113–119 ↗ | (On Diff #95955) | I'd appreciate if you can propose a refactoring before committing this patch (if possible) |
This patch is trivially LGTM based on the LangRef and discussion in PR32486:
https://bugs.llvm.org//show_bug.cgi?id=32486
Note, I don't qualify to LGTM as I'm not particularly familiar with vector code in LLVM.