[llvm] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 24 02:34:42 PDT 2023
================
@@ -1985,6 +1985,28 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
{InnerPtr, NewMask}));
}
}
+ bool Changed = false;
+ KnownBits Known = computeKnownBits(II, /*Depth*/ 0, II);
+ // See if we can deduce non-null.
+ if (!CI.hasRetAttr(Attribute::NonNull) &&
+ (Known.isNonZero() ||
+ isKnownNonZero(II, DL, /*Depth*/ 0, &AC, II, &DT))) {
+ CI.addRetAttr(Attribute::NonNull);
+ Changed = true;
+ }
+
+ // Known bits will capture if we had alignment information assosiated with
+ // the pointer argument.
+ if (Known.countMinTrailingZeros() > Log2(CI.getRetAlign().valueOrOne())) {
+ if (CI.hasRetAttr(Attribute::Alignment))
+ CI.removeRetAttr(Attribute::Alignment);
+ CI.addRetAttr(
+ Attribute::get(CI.getContext(), Attribute::Alignment,
+ uint64_t(1) << Known.countMinTrailingZeros()));
----------------
nikic wrote:
Attribute::getWithAlignment(). Also you need to protect against MaximumAlignment here.
https://github.com/llvm/llvm-project/pull/67166
More information about the llvm-commits
mailing list