Don't fold (select C, (gep Ptr, Idx), Ptr) if C is vector but Idx is scalar
authorYi Kong <yikong@google.com>
Wed, 22 Sep 2021 07:50:12 +0000 (15:50 +0800)
committerYi Kong <yikong@google.com>
Wed, 22 Sep 2021 10:11:33 +0000 (18:11 +0800)
commitd0746f2e9bbf08f52196ae12f25d0ef7edcbbe4c
treef8dd1b31eed7e3b22b91df99acffae13089d6f89
parent36daf074d997a79f25a1de2a1b869170ea6c20cc
Don't fold (select C, (gep Ptr, Idx), Ptr) if C is vector but Idx is scalar

The folding rule (select C, (gep Ptr, Idx), Ptr) -> (gep Ptr, (select C,
Idx, 0)) creates a malformed SELECT IR if C is a vector while Idx is scalar.

  SELECT VecC, ScalarIdx, 0

We could splat Idx to a vector but it defeats the purpose of
optimisation. Don't apply the folding rule in this case.

This fixes a regression from commit d561b6fbdbe6d1da05fd92003a4ac1e37bf4b8bc.
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/select-gep.ll