diff options
author | zGoldthorpe <zgoldtho@ualberta.ca> | 2025-08-15 10:43:54 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-15 10:43:54 -0600 |
commit | a8d25683eec612f180215f446397f39a53c5c416 (patch) | |
tree | b541eb5d47fa207cb40487a0a4d94e4c9f1a6258 /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | |
parent | af96ed6bf6e6a1ba0cbb36cb3925dd44f41c301e (diff) | |
download | llvm-a8d25683eec612f180215f446397f39a53c5c416.zip llvm-a8d25683eec612f180215f446397f39a53c5c416.tar.gz llvm-a8d25683eec612f180215f446397f39a53c5c416.tar.bz2 |
[PatternMatch] Allow `m_ConstantInt` to match integer splats (#153692)
When matching integers, `m_ConstantInt` is a convenient alternative to
`m_APInt` for matching unsigned 64-bit integers, allowing one to
simplify
```cpp
const APInt *IntC;
if (match(V, m_APInt(IntC))) {
if (IntC->ule(UINT64_MAX)) {
uint64_t Int = IntC->getZExtValue();
// ...
}
}
```
to
```cpp
uint64_t Int;
if (match(V, m_ConstantInt(Int))) {
// ...
}
```
However, this simplification is only true if `V` is a scalar type.
Specifically, `m_APInt` also matches integer splats, but `m_ConstantInt`
does not.
This patch ensures that the matching behaviour of `m_ConstantInt`
parallels that of `m_APInt`, and also incorporates it in some obvious
places.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 737321d..cc4eb2d 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -319,10 +319,10 @@ static void annotateNonNullAndDereferenceable(CallInst *CI, ArrayRef<unsigned> A annotateDereferenceableBytes(CI, ArgNos, LenC->getZExtValue()); } else if (isKnownNonZero(Size, DL)) { annotateNonNullNoUndefBasedOnAccess(CI, ArgNos); - const APInt *X, *Y; + uint64_t X, Y; uint64_t DerefMin = 1; - if (match(Size, m_Select(m_Value(), m_APInt(X), m_APInt(Y)))) { - DerefMin = std::min(X->getZExtValue(), Y->getZExtValue()); + if (match(Size, m_Select(m_Value(), m_ConstantInt(X), m_ConstantInt(Y)))) { + DerefMin = std::min(X, Y); annotateDereferenceableBytes(CI, ArgNos, DerefMin); } } |