From 3b7cf0aabafc1c7a89a5a978d4a4307c891027ce Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 17 Oct 2007 17:51:30 +0000 Subject: Define a helper function ConstantVector::getSplatValue for testing for and working with broadcasted constants. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43076 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Constants.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/VMCore') diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 350a306..9c1377d 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1286,6 +1286,17 @@ bool ConstantVector::isAllOnesValue() const { return true; } +/// getSplatValue - If this is a splat constant, where all of the +/// elements have the same value, return that value. Otherwise return null. +Constant *ConstantVector::getSplatValue() { + // Check out first element. + Constant *Elt = getOperand(0); + // Then make sure all remaining elements point to the same value. + for (unsigned I = 1, E = getNumOperands(); I < E; ++I) + if (getOperand(I) != Elt) return 0; + return Elt; +} + //---- ConstantPointerNull::get() implementation... // -- cgit v1.1