[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:44:03 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL341666: [InstCombine] Do not fold scalar ops over select with vector condition. (authored by fhahn, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51781?vs=164417&id=164418#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51781

Files:
  llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/trunk/test/Transforms/InstCombine/select-gep.ll


Index: llvm/trunk/test/Transforms/InstCombine/select-gep.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/select-gep.ll
+++ llvm/trunk/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: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/trunk/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.164418.patch
Type: text/x-patch
Size: 1834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180907/e0d8740d/attachment.bin>


More information about the llvm-commits mailing list