[PATCH] D51781: [InstCombine] Do not fold scalar ops over select with vector condition.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 7 07:31:44 PDT 2018
fhahn updated this revision to Diff 164417.
fhahn added a comment.
Adjusted comment and simplified test case.
https://reviews.llvm.org/D51781
Files:
lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/select-gep.ll
Index: test/Transforms/InstCombine/select-gep.ll
===================================================================
--- test/Transforms/InstCombine/select-gep.ll
+++ test/Transforms/InstCombine/select-gep.ll
@@ -136,3 +136,17 @@
ret i32* %select
}
+; We cannot create a select with a vector condition but scalar operands.
+
+define <2 x i64*> @test5(i64* %p1, i64* %p2, <2 x i64> %idx, <2 x i1> %cc) {
+; CHECK-LABEL: @test5(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i64, i64* %p1, <2 x i64> %idx
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i64, i64* %p2, <2 x i64> %idx
+; CHECK-NEXT: [[SELECT:%.*]] = select <2 x i1> %cc, <2 x i64*> [[GEP1]], <2 x i64*> [[GEP2]]
+; CHECK-NEXT: ret <2 x i64*> [[SELECT]]
+;
+ %gep1 = getelementptr i64, i64* %p1, <2 x i64> %idx
+ %gep2 = getelementptr i64, i64* %p2, <2 x i64> %idx
+ %select = select <2 x i1> %cc, <2 x i64*> %gep1, <2 x i64*> %gep2
+ ret <2 x i64*> %select
+}
Index: lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -362,6 +362,14 @@
return nullptr;
}
+ // If the select condition is a vector, the operands of the original select's
+ // operands also must be vectors. This may not be the case for getelementptr
+ // for example.
+ if (SI.getCondition()->getType()->isVectorTy() &&
+ (!OtherOpT->getType()->isVectorTy() ||
+ !OtherOpF->getType()->isVectorTy()))
+ return nullptr;
+
// If we reach here, they do have operations in common.
Value *NewSI = Builder.CreateSelect(SI.getCondition(), OtherOpT, OtherOpF,
SI.getName() + ".v", &SI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51781.164417.patch
Type: text/x-patch
Size: 1768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180907/f5872d47/attachment.bin>
More information about the llvm-commits
mailing list