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

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 24 02:34:37 PDT 2023


================
@@ -1984,10 +1984,30 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     //    -> (ptrmask p, (and A, B))
     if (match(Op0, m_OneUse(m_Intrinsic<Intrinsic::ptrmask>(
                        m_Value(InnerPtr), m_Value(InnerMask))))) {
+      // See if combining the two masks is free.
+      bool OkayToMerge = InnerMask->getType() == Op1->getType();
+      bool NeedsNew = false;
+      if (!OkayToMerge) {
+        if (match(InnerMask, m_ImmConstant())) {
+          InnerMask = Builder.CreateZExtOrTrunc(InnerMask, Op1->getType());
+          OkayToMerge = true;
+        } else if (match(Op1, m_ImmConstant())) {
+          Op1 = Builder.CreateZExtOrTrunc(Op1, InnerMask->getType());
+          OkayToMerge = true;
+          // Need to create a new one here, as the intrinsic id needs to change.
+          NeedsNew = true;
+        }
+      }
----------------
nikic wrote:

This is the wrong approach. You should be canonicalizing the second operand to match the pointer size instead and then let the usual folds handle the rest.

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


More information about the cfe-commits mailing list