[llvm] [IR] Simplify comparisons with std::optional (NFC) (PR #105624)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 00:08:05 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/105624

For variable X of type std::optional, X && X.has_value(Y) == Z is
equivalent to X == Z.


>From 16ca173548d1d55c6345372e6cb9fe9d6f3e5742 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 21 Aug 2024 21:52:03 -0700
Subject: [PATCH] [IR] Simplify comparisons with std::optional (NFC)

For variable X of type std::optional, X && X.has_value(Y) == Z is
equivalent to X == Z.
---
 llvm/lib/IR/VectorBuilder.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/IR/VectorBuilder.cpp b/llvm/lib/IR/VectorBuilder.cpp
index 8dbf25277bf5d2..b8f56a7a2e5f9b 100644
--- a/llvm/lib/IR/VectorBuilder.cpp
+++ b/llvm/lib/IR/VectorBuilder.cpp
@@ -96,8 +96,7 @@ Value *VectorBuilder::createVectorInstructionImpl(Intrinsic::ID VPID,
     // Insert mask and evl operands in between the instruction operands.
     for (size_t VPParamIdx = 0, ParamIdx = 0; VPParamIdx < NumVPParams;
          ++VPParamIdx) {
-      if ((MaskPosOpt && MaskPosOpt.value_or(NumVPParams) == VPParamIdx) ||
-          (VLenPosOpt && VLenPosOpt.value_or(NumVPParams) == VPParamIdx))
+      if (MaskPosOpt == VPParamIdx || VLenPosOpt == VPParamIdx)
         continue;
       assert(ParamIdx < NumInstParams);
       IntrinParams[VPParamIdx] = InstOpArray[ParamIdx++];



More information about the llvm-commits mailing list