[PATCH] Fold selects when the non-selected elements are undef from shufflevectors
Benjamin Kramer
benny.kra at gmail.com
Fri May 2 10:20:33 PDT 2014
================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:739
@@ +738,3 @@
+ ShuffleVectorInst *FalseSV = dyn_cast<ShuffleVectorInst>(FalseVal);
+ if (!(VecTy && TrueSV && FalseSV))
+ return false;
----------------
IMO DeMorgan's law makes this kind of condition more readable
if (!VecTy || !TrueSV || !FalseSV)
================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:743
@@ +742,3 @@
+ ConstantVector *CondV = dyn_cast<ConstantVector>(CondVal);
+ if (!(CondV && SI.hasOneUse()))
+ return false;
----------------
Why is it important that SI has only one use?
================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:756-758
@@ +755,5 @@
+ // shufflevector <4 x i32> <2 x i32>
+ VectorType *TrueShuffleSrc = cast<VectorType>(TrueV2->getType());
+ VectorType *FalseShuffleSrc = cast<VectorType>(FalseV2->getType());
+ if (TrueShuffleSrc != FalseShuffleSrc)
+ return false;
----------------
Since you never use any VectorType methods you can skip the cast<>s here.
================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:778
@@ +777,3 @@
+ if (!Element) {
+ ShuffleMask.push_back(-1);
+ continue;
----------------
If it's not a ConstantInt it could also be a ConstantExpr instead of an Undef. You probably want to bail out in that case.
http://reviews.llvm.org/D3561
More information about the llvm-commits
mailing list