[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 06:11:12 PDT 2018


fhahn created this revision.
fhahn added reviewers: spatel, john.brawn, mssimpso, craig.topper.

If OtherOpT or OtherOpF have scalar types and the condition is a vector,
we would create an invalid select.


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,21 @@
   ret i32* %select
 }
 
+; We cannot turn create a select with a vector condition but scalar operands.
+
+define <2 x i64*> @test5(i64* %p, <2 x i1> %cc) {
+; CHECK-LABEL: @test5(
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr i64, i64* [[P:%.*]], i64 -1
+; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr i64, i64* [[P]], i64 1
+; CHECK-NEXT:    [[GEP3:%.*]] = getelementptr i64, i64* [[GEP1]], <2 x i64> undef
+; CHECK-NEXT:    [[GEP4:%.*]] = getelementptr i64, i64* [[GEP2]], <2 x i64> undef
+; CHECK-NEXT:    [[SELECT:%.*]] = select <2 x i1> [[CC:%.*]], <2 x i64*> [[GEP3]], <2 x i64*> [[GEP4]]
+; CHECK-NEXT:    ret <2 x i64*> [[SELECT]]
+;
+  %gep1 = getelementptr i64, i64* %p, i64 -1
+  %gep2 = getelementptr i64, i64* %p, i64 1
+  %gep3 = getelementptr i64, i64* %gep1, <2 x i64> undef
+  %gep4 = getelementptr i64, i64* %gep2, <2 x i64> undef
+  %select = select <2 x i1> %cc, <2 x i64*> %gep3, <2 x i64*> %gep4
+  ret <2 x i64*> %select
+}
Index: lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -362,6 +362,12 @@
     return nullptr;
   }
 
+  // If the select condition is a vector, the operands also must be vectors.
+  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.164396.patch
Type: text/x-patch
Size: 1905 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180907/9cc7457c/attachment.bin>


More information about the llvm-commits mailing list