[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 25 01:07:07 PDT 2023


================
@@ -1973,6 +1978,28 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
           *II, Builder.CreateIntrinsic(InnerPtr->getType(), Intrinsic::ptrmask,
                                        {InnerPtr, NewMask}));
     }
+    bool Changed = false;
+    // 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;
+    }
+
+    unsigned NewAlignmentLog =
+        std::min(Value::MaxAlignmentExponent,
+                 std::min(BitWidth - 1, Known.countMinTrailingZeros()));
+    // Known bits will capture if we had alignment information associated with
+    // the pointer argument.
+    if (NewAlignmentLog > Log2(CI.getRetAlign().valueOrOne())) {
+      CI.removeRetAttr(Attribute::Alignment);
----------------
nikic wrote:

No need to explicitly remove the old attribute.

https://github.com/llvm/llvm-project/pull/67166


More information about the cfe-commits mailing list