[PATCH] D44997: [InstCombine] Fold compare of int constant against a splatted vector of ints
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 3 09:20:45 PDT 2018
spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.
LGTM - see inline comments for more small improvements.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2475-2476
+ Value *BCIOp = Bitcast->getOperand(0);
+ Value *Vec = nullptr; // 1st vector arg of the shufflevector
+ Constant *Mask = nullptr; // Mask arg of the shufflevector
+ if (match(BCIOp,
----------------
No need to explicitly set these to nullptr; if the match fails, we don't use those variables.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2482
+ auto *VecTy = cast<VectorType>(BCIOp->getType());
+ auto *ValTy = cast<IntegerType>(VecTy->getElementType());
+ auto Pred = Cmp.getPredicate();
----------------
Slightly less generic if you name this 'EltTy' or similar to indicate that it's the element's type.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2492-2493
+ Value *NewC = ConstantInt::get(ValTy, C.trunc(ValTy->getBitWidth()));
+ return replaceInstUsesWith(Cmp,
+ Builder.CreateICmp(Pred, Extract, NewC));
+ }
----------------
Less code if we let instcombine handle the replacement:
return new ICmpInst(Pred, Extract, NewC);
================
Comment at: test/Transforms/InstCombine/icmp-bc-vec.ll:12-13
+; Into:
+; %E = extractelement <M x iK> %vec, i32 C'
+; icmp <pred> iK %E, trunc(C)
+
----------------
We should have a test that shows this most basic transform (the extractelt is in the output). I'd also include a test with a shuffle that changes the number of elements, and a test with weird types...so all-in-one:
```
define i1 @extending_shuffle_with_weird_types(<2 x i9> %v) {
%splat = shufflevector <2 x i9> %v, <2 x i9> undef, <3 x i32> zeroinitializer
%cast = bitcast <3 x i9> %splat to i27
%cmp = icmp slt i27 %cast, 262657 ; 0x040201
ret i1 %cmp
}
```
Repository:
rL LLVM
https://reviews.llvm.org/D44997
More information about the llvm-commits
mailing list