]> granicus.if.org Git - llvm/commitdiff
[InferAddressSpaces] Fix crash on select of non-ptr operands
authorJoey Gouly <joey.gouly@gmail.com>
Thu, 21 Feb 2019 12:31:36 +0000 (12:31 +0000)
committerJoey Gouly <joey.gouly@gmail.com>
Thu, 21 Feb 2019 12:31:36 +0000 (12:31 +0000)
Check the operands of a select are pointers, to determine if it is an address
expression or not.

https://reviews.llvm.org/D58226

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354576 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InferAddressSpaces.cpp
test/Transforms/InferAddressSpaces/AMDGPU/infer-address-space.ll

index 14fa24bf105f4b511ccf7c34489b9982249e9a68..8f5ddf7f9f94901d6de7e631228e4154ece926da 100644 (file)
@@ -217,13 +217,16 @@ static bool isAddressExpression(const Value &V) {
   if (!isa<Operator>(V))
     return false;
 
-  switch (cast<Operator>(V).getOpcode()) {
+  const Operator &Op = cast<Operator>(V);
+  switch (Op.getOpcode()) {
   case Instruction::PHI:
+    assert(Op.getType()->isPointerTy());
   case Instruction::BitCast:
   case Instruction::AddrSpaceCast:
   case Instruction::GetElementPtr:
-  case Instruction::Select:
     return true;
+  case Instruction::Select:
+    return Op.getType()->isPointerTy();
   default:
     return false;
   }
index 3096d8144dcc0bd6f28b1c0599592aa87af8d3c6..2f6d2b85d3e2987fc90eabf1f1f075ae715b0f0d 100644 (file)
@@ -168,6 +168,15 @@ exit:                                             ; preds = %loop
   ret void
 }
 
+; CHECK-LABEL: @select_bug(
+; CHECK: %add.ptr157 = getelementptr inbounds i64, i64* undef, i64 select (i1 icmp ne (i32* inttoptr (i64 4873 to i32*), i32* null), i64 73, i64 93)
+; CHECK: %cmp169 = icmp uge i64* undef, %add.ptr157
+define void @select_bug() #0 {
+  %add.ptr157 = getelementptr inbounds i64, i64* undef, i64 select (i1 icmp ne (i32* inttoptr (i64 4873 to i32*), i32* null), i64 73, i64 93)
+  %cmp169 = icmp uge i64* undef, %add.ptr157
+  unreachable
+}
+
 declare void @llvm.amdgcn.s.barrier() #1
 declare void @use(float) #0