From 06ebbcc71de34fdbf6e652b2b48a2d50b6331ddc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 5 Jan 2009 23:45:50 +0000 Subject: make m_ConstantInt(int64_t) safely match ConstantInt's that are larger than i64. This fixes an instcombine crash on PR3235. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61775 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/PatternMatch.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include/llvm/Support/PatternMatch.h') diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index 035dcf513f..55b4b6a74c 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -57,7 +57,16 @@ struct constantint_ty { template bool match(ITy *V) { - return isa(V) && cast(V)->getSExtValue() == Val; + if (const ConstantInt *CI = dyn_cast(V)) { + const APInt &CIV = CI->getValue(); + if (Val > 0) + return CIV == Val; + // If Val is negative, and CI is shorter than it, truncate to the right + // number of bits. If it is larger, then we have to sign extend. Just + // compare their negated values. + return -CIV == -Val; + } + return false; } }; -- cgit v1.2.3-18-g5258