[PATCH] D156638: [InstCombine] Preserve return attributes when merging `llvm.ptrmask`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 30 16:01:37 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, RKSimon.
Herald added subscribers: StephenFan, hiraditya, arichardson.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156638
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/ptrmask.ll
Index: llvm/test/Transforms/InstCombine/ptrmask.ll
===================================================================
--- llvm/test/Transforms/InstCombine/ptrmask.ll
+++ llvm/test/Transforms/InstCombine/ptrmask.ll
@@ -8,7 +8,7 @@
; 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)
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1944,18 +1944,21 @@
"support vector types and may not work for vectors");
Value *InnerPtr, *InnerMask;
- if (match(II->getArgOperand(0),
- m_OneUse(m_Intrinsic<Intrinsic::ptrmask>(m_Value(InnerPtr),
- m_Value(InnerMask))))) {
- if (II->getArgOperand(1)->getType() == InnerMask->getType()) {
- Value *NewMask = Builder.CreateAnd(II->getArgOperand(1), InnerMask);
- return replaceInstUsesWith(
- *II,
- Builder.CreateIntrinsic(InnerPtr->getType(), Intrinsic::ptrmask,
- {InnerPtr, NewMask}));
+ bool Changed = false;
+ // Combine:
+ // (ptrmask (ptrmask p, A), B)
+ // -> (ptrmask p, (and A, B))
+ if (match(Op0, m_OneUse(m_Intrinsic<Intrinsic::ptrmask>(
+ m_Value(InnerPtr), m_Value(InnerMask))))) {
+ if (InnerMask->getType() == Op1->getType()) {
+ // TODO: If InnerMask == Op1, we could copy attributes from inner
+ // callsite -> outer callsite.
+ Value *NewMask = Builder.CreateAnd(Op1, InnerMask);
+ 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() ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156638.545482.patch
Type: text/x-patch
Size: 2343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230730/8654f433/attachment.bin>
More information about the llvm-commits
mailing list