[PATCH] Fix lint assert on integer vector division
Matt Arsenault
Matthew.Arsenault at amd.com
Wed Aug 14 18:31:45 PDT 2013
Make the zero check actually work for vectors
http://llvm-reviews.chandlerc.com/D1408
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1408?vs=3487&id=3490#toc
Files:
lib/Analysis/Lint.cpp
test/Analysis/Lint/check-zero-vector.ll
Index: lib/Analysis/Lint.cpp
===================================================================
--- lib/Analysis/Lint.cpp
+++ lib/Analysis/Lint.cpp
@@ -509,10 +509,37 @@
if (isa<UndefValue>(V))
return true;
- unsigned BitWidth = V->getType()->getScalarType()->getIntegerBitWidth();
- APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
- ComputeMaskedBits(V, KnownZero, KnownOne, DL);
- return KnownZero.isAllOnesValue();
+ if (!V->getType()->isVectorTy()) {
+ unsigned BitWidth = V->getType()->getIntegerBitWidth();
+ APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
+ ComputeMaskedBits(V, KnownZero, KnownOne, DL);
+ return KnownZero.isAllOnesValue();
+ }
+
+ // Per-component check doesn't work with zeroinitializer
+ Constant *C = dyn_cast<Constant>(V);
+ if (C && C->isZeroValue())
+ return true;
+
+ // For a vector, this will only be true if all values are zero, so check this
+ // per component
+ ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C);
+ if (!CDS)
+ return false;
+
+ unsigned BitWidth = CDS->getElementType()->getIntegerBitWidth();
+ for (unsigned I = 0, N = CDS->getNumElements(); I != N; ++I) {
+ APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
+ Constant *Elem = CDS->getElementAsConstant(I);
+ if (isa<UndefValue>(Elem))
+ return true;
+
+ ComputeMaskedBits(Elem, KnownZero, KnownOne, DL);
+ if (KnownZero.isAllOnesValue())
+ return true;
+ }
+
+ return false;
}
void Lint::visitSDiv(BinaryOperator &I) {
Index: test/Analysis/Lint/check-zero-vector.ll
===================================================================
--- test/Analysis/Lint/check-zero-vector.ll
+++ test/Analysis/Lint/check-zero-vector.ll
@@ -1,4 +1,4 @@
-; RUN: opt -lint < %s
+; RUN: opt -lint -disable-output %s 2>&1 | FileCheck %s
define <2 x i32> @use_vector_sdiv(<2 x i32> %a) nounwind {
%b = sdiv <2 x i32> %a, <i32 5, i32 8>
@@ -18,4 +18,25 @@
define <2 x i32> @use_vector_urem(<2 x i32> %a) nounwind {
%b = urem <2 x i32> %a, <i32 5, i32 8>
ret <2 x i32> %b
-}
\ No newline at end of file
+}
+
+define <2 x i32> @use_vector_sdiv_by_zero_x(<2 x i32> %a) nounwind {
+; CHECK: Undefined behavior: Division by zero
+; CHECK-NEXT: %b = sdiv <2 x i32> %a, <i32 0, i32 5>
+ %b = sdiv <2 x i32> %a, <i32 0, i32 5>
+ ret <2 x i32> %b
+}
+
+define <2 x i32> @use_vector_sdiv_by_zero_y(<2 x i32> %a) nounwind {
+; CHECK: Undefined behavior: Division by zero
+; CHECK-NEXT: %b = sdiv <2 x i32> %a, <i32 4, i32 0>
+ %b = sdiv <2 x i32> %a, <i32 4, i32 0>
+ ret <2 x i32> %b
+}
+
+define <2 x i32> @use_vector_sdiv_by_zero_xy(<2 x i32> %a) nounwind {
+; CHECK: Undefined behavior: Division by zero
+; CHECK-NEXT: %b = sdiv <2 x i32> %a, zeroinitializer
+ %b = sdiv <2 x i32> %a, <i32 0, i32 0>
+ ret <2 x i32> %b
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1408.2.patch
Type: text/x-patch
Size: 2826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130814/25ec24fd/attachment.bin>
More information about the llvm-commits
mailing list