Skip to content

Commit 03f616e

Browse files
[llvm] Compare std::optional<T> to values directly (NFC) (#143340)
This patch transforms: X && *X == Y to: X == Y where X is of std::optional<T>, and Y is of T or similar.
1 parent 3dabeed commit 03f616e

File tree

12 files changed

+16
-18
lines changed

12 files changed

+16
-18
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ bool llvm::isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL,
16221622
std::optional<int64_t> Diff =
16231623
getPointersDiff(ElemTyA, PtrA, ElemTyB, PtrB, DL, SE,
16241624
/*StrictCheck=*/true, CheckType);
1625-
return Diff && *Diff == 1;
1625+
return Diff == 1;
16261626
}
16271627

16281628
void MemoryDepChecker::addAccess(StoreInst *SI) {

llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ static bool printCompactDWARFExpr(
499499
break;
500500
}
501501
case dwarf::DW_OP_LLVM_user: {
502-
assert(Op.getSubCode() && *Op.getSubCode() == dwarf::DW_OP_LLVM_nop);
502+
assert(Op.getSubCode() == dwarf::DW_OP_LLVM_nop);
503503
break;
504504
}
505505
default:

llvm/lib/ObjCopy/MachO/MachOObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct Section {
7171
}
7272

7373
bool hasValidOffset() const {
74-
return !(isVirtualSection() || (OriginalOffset && *OriginalOffset == 0));
74+
return !(isVirtualSection() || OriginalOffset == 0);
7575
}
7676
};
7777

llvm/lib/Object/ELFObjectFile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
736736
case ARMBuildAttrs::v7: {
737737
std::optional<unsigned> ArchProfileAttr =
738738
Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile);
739-
if (ArchProfileAttr &&
740-
*ArchProfileAttr == ARMBuildAttrs::MicroControllerProfile)
739+
if (ArchProfileAttr == ARMBuildAttrs::MicroControllerProfile)
741740
Triple += "v7m";
742741
else
743742
Triple += "v7";

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5870,19 +5870,19 @@ SDValue AArch64TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
58705870
// If the operand is an higher half itself, rewrite it to
58715871
// extract_high_v2i64; this way aarch64_neon_pmull64 could
58725872
// re-use the dag-combiner function with aarch64_neon_{pmull,smull,umull}.
5873-
if (NLane && *NLane == 1)
5873+
if (NLane == 1)
58745874
return DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v1i64,
58755875
N.getOperand(0), DAG.getConstant(1, dl, MVT::i64));
58765876

58775877
// Operand N is not a higher half but the other operand is.
5878-
if (OtherLane && *OtherLane == 1) {
5878+
if (OtherLane == 1) {
58795879
// If this operand is a lower half, rewrite it to
58805880
// extract_high_v2i64(duplane(<2 x Ty>, 0)). This saves a roundtrip to
58815881
// align lanes of two operands. A roundtrip sequence (to move from lane
58825882
// 1 to lane 0) is like this:
58835883
// mov x8, v0.d[1]
58845884
// fmov d0, x8
5885-
if (NLane && *NLane == 0)
5885+
if (NLane == 0)
58865886
return DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v1i64,
58875887
DAG.getNode(AArch64ISD::DUPLANE64, dl, MVT::v2i64,
58885888
N.getOperand(0),

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4263,7 +4263,7 @@ static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI) {
42634263
if (MI.getOpcode() != TargetOpcode::G_XOR)
42644264
return false;
42654265
auto ConstVal = getIConstantVRegSExtVal(MI.getOperand(2).getReg(), MRI);
4266-
return ConstVal && *ConstVal == -1;
4266+
return ConstVal == -1;
42674267
}
42684268

42694269
// Return the use branch instruction, otherwise null if the usage is invalid.

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5232,8 +5232,7 @@ struct AAFoldRuntimeCallCallSiteReturned : AAFoldRuntimeCall {
52325232
IRPosition::callsite_returned(CB),
52335233
[&](const IRPosition &IRP, const AbstractAttribute *AA,
52345234
bool &UsedAssumedInformation) -> std::optional<Value *> {
5235-
assert((isValidState() ||
5236-
(SimplifiedValue && *SimplifiedValue == nullptr)) &&
5235+
assert((isValidState() || SimplifiedValue == nullptr) &&
52375236
"Unexpected invalid state!");
52385237

52395238
if (!isAtFixpoint()) {

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,9 @@ void State::addInfoForInductions(BasicBlock &BB) {
10101010
auto IncUnsigned = SE.getMonotonicPredicateType(AR, CmpInst::ICMP_UGT);
10111011
auto IncSigned = SE.getMonotonicPredicateType(AR, CmpInst::ICMP_SGT);
10121012
bool MonotonicallyIncreasingUnsigned =
1013-
IncUnsigned && *IncUnsigned == ScalarEvolution::MonotonicallyIncreasing;
1013+
IncUnsigned == ScalarEvolution::MonotonicallyIncreasing;
10141014
bool MonotonicallyIncreasingSigned =
1015-
IncSigned && *IncSigned == ScalarEvolution::MonotonicallyIncreasing;
1015+
IncSigned == ScalarEvolution::MonotonicallyIncreasing;
10161016
// If SCEV guarantees that AR does not wrap, PN >= StartValue can be added
10171017
// unconditionally.
10181018
if (MonotonicallyIncreasingUnsigned)

llvm/lib/Transforms/Utils/Debugify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ bool diagnoseMisSizedDbgValue(Module &M, DbgValTy *DbgVal) {
705705
bool HasBadSize = false;
706706
if (Ty->isIntegerTy()) {
707707
auto Signedness = DbgVal->getVariable()->getSignedness();
708-
if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
708+
if (Signedness == DIBasicType::Signedness::Signed)
709709
HasBadSize = ValueOperandSize < *DbgVarSize;
710710
} else {
711711
HasBadSize = ValueOperandSize != *DbgVarSize;

llvm/tools/llvm-cov/SourceCoverageViewText.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ void SourceCoverageViewText::renderLine(raw_ostream &OS, LineRef L,
186186
if (getOptions().Debug && Highlight)
187187
HighlightedRanges.push_back(std::make_pair(Col, End));
188188
Col = End;
189-
if ((!S->IsGapRegion || (Highlight && *Highlight == raw_ostream::RED)) &&
190-
S->HasCount && S->Count == 0)
189+
if ((!S->IsGapRegion || Highlight == raw_ostream::RED) && S->HasCount &&
190+
S->Count == 0)
191191
Highlight = raw_ostream::RED;
192192
else if (Col == ExpansionCol)
193193
Highlight = raw_ostream::CYAN;

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ struct VPMatchContext : public SDPatternMatch::BasicMatchContext {
567567
return OpVal->getOpcode() == Opc;
568568

569569
auto BaseOpc = ISD::getBaseOpcodeForVP(OpVal->getOpcode(), false);
570-
return BaseOpc.has_value() && *BaseOpc == Opc;
570+
return BaseOpc == Opc;
571571
}
572572

573573
unsigned getNumOperands(SDValue N) const {

llvm/unittests/Support/ARMAttributeParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bool testBuildAttr(unsigned Tag, unsigned Value,
3838
cantFail(Parser.parse(Bytes, llvm::endianness::little));
3939

4040
std::optional<unsigned> Attr = Parser.getAttributeValue("", ExpectedTag);
41-
return Attr && *Attr == ExpectedValue;
41+
return Attr == ExpectedValue;
4242
}
4343

4444
void testParseError(ArrayRef<uint8_t> bytes, const char *msg) {

0 commit comments

Comments
 (0)