[llvm] r336442 - [Constant] add undef element query for vector constants; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 6 07:52:36 PDT 2018
Author: spatel
Date: Fri Jul 6 07:52:36 2018
New Revision: 336442
URL: http://llvm.org/viewvc/llvm-project?rev=336442&view=rev
Log:
[Constant] add undef element query for vector constants; NFC
This is likely to be used in D48987 and similar patches,
so adding it as an NFC preliminary step.
Modified:
llvm/trunk/include/llvm/IR/Constant.h
llvm/trunk/lib/IR/Constants.cpp
Modified: llvm/trunk/include/llvm/IR/Constant.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Constant.h?rev=336442&r1=336441&r2=336442&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Constant.h (original)
+++ llvm/trunk/include/llvm/IR/Constant.h Fri Jul 6 07:52:36 2018
@@ -87,6 +87,10 @@ public:
/// floating-point constant with all NaN elements.
bool isNaN() const;
+ /// Return true if this is a vector constant that includes any undefined
+ /// elements.
+ bool containsUndefElement() const;
+
/// Return true if evaluation of this constant could trap. This is true for
/// things like constant expressions that could divide by zero.
bool canTrap() const;
Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=336442&r1=336441&r2=336442&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Fri Jul 6 07:52:36 2018
@@ -254,6 +254,16 @@ bool Constant::isNaN() const {
return true;
}
+bool Constant::containsUndefElement() const {
+ if (!getType()->isVectorTy())
+ return false;
+ for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i)
+ if (isa<UndefValue>(getAggregateElement(i)))
+ return true;
+
+ return false;
+}
+
/// Constructor to create a '0' constant of arbitrary type.
Constant *Constant::getNullValue(Type *Ty) {
switch (Ty->getTypeID()) {
More information about the llvm-commits
mailing list