[llvm] cc83418 - [InstCombine] Preserve return attributes when merging `llvm.ptrmask`
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 1 21:50:59 PDT 2023
Author: Noah Goldstein
Date: 2023-11-01T23:50:36-05:00
New Revision: cc8341872d48ed3b7d4c42cac32d68349644c1c1
URL: https://github.com/llvm/llvm-project/commit/cc8341872d48ed3b7d4c42cac32d68349644c1c1
DIFF: https://github.com/llvm/llvm-project/commit/cc8341872d48ed3b7d4c42cac32d68349644c1c1.diff
LOG: [InstCombine] Preserve return attributes when merging `llvm.ptrmask`
If we have assosiated attributes i.e `([ret_attrs] (ptrmask (ptrmask
p0, m0), m1))` we should preserve `[ret_attrs]` when combining the two
`llvm.ptrmask`s.
Differential Revision: https://reviews.llvm.org/D156638
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/ptrmask.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 10a8bff700b7366..b0d31a92464e375 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1968,17 +1968,23 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
return II;
Value *InnerPtr, *InnerMask;
+ bool Changed = false;
+ // Combine:
+ // (ptrmask (ptrmask p, A), B)
+ // -> (ptrmask p, (and A, B))
if (match(II->getArgOperand(0),
m_OneUse(m_Intrinsic<Intrinsic::ptrmask>(m_Value(InnerPtr),
m_Value(InnerMask))))) {
assert(II->getArgOperand(1)->getType() == InnerMask->getType() &&
"Mask types must match");
+ // TODO: If InnerMask == Op1, we could copy attributes from inner
+ // callsite -> outer callsite.
Value *NewMask = Builder.CreateAnd(II->getArgOperand(1), InnerMask);
- return replaceInstUsesWith(
- *II, Builder.CreateIntrinsic(InnerPtr->getType(), Intrinsic::ptrmask,
- {InnerPtr, NewMask}));
+ replaceOperand(CI, 0, InnerPtr);
+ replaceOperand(CI, 1, NewMask);
+ Changed = true;
}
- bool Changed = false;
+
// See if we can deduce non-null.
if (!CI.hasRetAttr(Attribute::NonNull) &&
(Known.isNonZero() ||
diff --git a/llvm/test/Transforms/InstCombine/ptrmask.ll b/llvm/test/Transforms/InstCombine/ptrmask.ll
index c501062b3b3b05b..b07b81e32cbc74f 100644
--- a/llvm/test/Transforms/InstCombine/ptrmask.ll
+++ b/llvm/test/Transforms/InstCombine/ptrmask.ll
@@ -12,7 +12,7 @@ define ptr @ptrmask_combine_consecutive_preserve_attrs(ptr %p0, i64 %m1) {
; CHECK-LABEL: define ptr @ptrmask_combine_consecutive_preserve_attrs
; CHECK-SAME: (ptr [[P0:%.*]], i64 [[M1:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[M1]], 224
-; CHECK-NEXT: [[R:%.*]] = call align 32 ptr @llvm.ptrmask.p0.i64(ptr [[P0]], i64 [[TMP1]])
+; CHECK-NEXT: [[R:%.*]] = call noalias align 32 ptr @llvm.ptrmask.p0.i64(ptr [[P0]], i64 [[TMP1]])
; CHECK-NEXT: ret ptr [[R]]
;
%pm0 = call ptr @llvm.ptrmask.p0.i64(ptr %p0, i64 224)
@@ -24,7 +24,7 @@ define <2 x ptr> @ptrmask_combine_consecutive_preserve_attrs_vecs(<2 x ptr> %p0,
; CHECK-LABEL: define <2 x ptr> @ptrmask_combine_consecutive_preserve_attrs_vecs
; CHECK-SAME: (<2 x ptr> [[P0:%.*]], <2 x i64> [[M1:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i64> [[M1]], <i64 12345, i64 12345>
-; CHECK-NEXT: [[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> [[P0]], <2 x i64> [[TMP1]])
+; CHECK-NEXT: [[R:%.*]] = call align 128 <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> [[P0]], <2 x i64> [[TMP1]])
; CHECK-NEXT: ret <2 x ptr> [[R]]
;
%pm0 = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> %p0, <2 x i64> <i64 12345, i64 12345>)
More information about the llvm-commits
mailing list