diff options
Diffstat (limited to 'include/llvm/Support/PatternMatch.h')
-rw-r--r-- | include/llvm/Support/PatternMatch.h | 11 |
1 files changed, 10 insertions, 1 deletions
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<typename ITy> bool match(ITy *V) { - return isa<ConstantInt>(V) && cast<ConstantInt>(V)->getSExtValue() == Val; + if (const ConstantInt *CI = dyn_cast<ConstantInt>(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; } }; |