[PATCH] D38369: [InstSimplify] teach SimplifySelectInst() to fold more vector selects
Haicheng Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 28 09:55:20 PDT 2017
haicheng created this revision.
Herald added a subscriber: mcrosier.
Call ConstantExpr::getSelect() to fold cases like below
`select <2 x i1><i1 true, i1 false>, <2 x i8> <i8 0, i8 1>, <2 x i8> <i8 2, i8 3>`
All operands are constants and the condition has mixed true and false conditions
Repository:
rL LLVM
https://reviews.llvm.org/D38369
Files:
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/select.ll
Index: test/Transforms/InstSimplify/select.ll
===================================================================
--- test/Transforms/InstSimplify/select.ll
+++ test/Transforms/InstSimplify/select.ll
@@ -17,6 +17,14 @@
ret <2 x i8> %s
}
+define <2 x i8> @vsel_mixedvec() {
+; CHECK-LABEL: @vsel_mixedvec(
+; CHECK-NEXT: ret <2 x i8> <i8 0, i8 3>
+;
+ %s = select <2 x i1><i1 true, i1 false>, <2 x i8> <i8 0, i8 1>, <2 x i8> <i8 2, i8 3>
+ ret <2 x i8> %s
+}
+
define i32 @test1(i32 %x) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i32 %x
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -3580,6 +3580,9 @@
// select true, X, Y -> X
// select false, X, Y -> Y
if (Constant *CB = dyn_cast<Constant>(CondVal)) {
+ if (Constant *CT = dyn_cast<Constant>(TrueVal))
+ if (Constant *CF = dyn_cast<Constant>(FalseVal))
+ return ConstantExpr::getSelect(CB, CT, CF);
if (CB->isAllOnesValue())
return TrueVal;
if (CB->isNullValue())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38369.117012.patch
Type: text/x-patch
Size: 1126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170928/77d547e2/attachment.bin>
More information about the llvm-commits
mailing list