Update for comment
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index 2ea82af..5838109 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h
@@ -182,8 +182,7 @@ Align Alignment; AtomicOrdering Ordering; SyncScope::ID SSID; - // TODO: Add IsElementwise here once StoreInst also supports the elementwise - // modifier. + bool IsElementwise = false; }; /// An instruction for reading from memory. This uses the SubclassData field in @@ -213,12 +212,8 @@ LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, Align Align, InsertPosition InsertBefore = nullptr); LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, - Align Align, AtomicOrdering Order, SyncScope::ID SSID, - InsertPosition InsertBefore); - LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, Align Align, AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System, - bool IsElementwise = false, InsertPosition InsertBefore = nullptr); LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, const LoadStoreInstProperties &Props, @@ -275,7 +270,8 @@ /// Returns the properties of this load instruction. LoadStoreInstProperties getProperties() const { - return {isVolatile(), getAlign(), getOrdering(), getSyncScopeID()}; + return {isVolatile(), getAlign(), getOrdering(), getSyncScopeID(), + isElementwise()}; } /// Sets the properties of this load instruction. @@ -284,6 +280,7 @@ setAlignment(Props.Alignment); setOrdering(Props.Ordering); setSyncScopeID(Props.SSID); + setElementwise(Props.IsElementwise); } bool isSimple() const { return !isAtomic() && !isVolatile(); }
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index bb5c429..c58b109 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -9020,8 +9020,9 @@ return error(ExplicitTypeLoc, "loading unsized types is not allowed"); if (!Alignment) Alignment = M->getDataLayout().getABITypeAlign(Ty); - Inst = new LoadInst(Ty, Val, "", isVolatile, *Alignment, Ordering, SSID, - IsElementwise, + Inst = new LoadInst(Ty, Val, "", + LoadStoreInstProperties{isVolatile, *Alignment, Ordering, + SSID, IsElementwise}, /*InsertBefore=*/nullptr); return AteExtraComma ? InstExtraComma : InstNormal; }
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 11ff561..bb8772e 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -6484,9 +6484,11 @@ return Err; if (!Align) return error("Alignment missing from atomic load"); - I = new LoadInst(Ty, Op, "", Record[OpNum + 1], *Align, Ordering, SSID, - IsElementwise, - /*InsertBefore=*/nullptr); + I = new LoadInst( + Ty, Op, "", + LoadStoreInstProperties{/*IsVolatile=*/Record[OpNum + 1] != 0, *Align, + Ordering, SSID, IsElementwise}, + /*InsertBefore=*/nullptr); InstructionList.push_back(I); break; }
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 73957c0..c8f2da7 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp
@@ -1363,28 +1363,23 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, Align Align, InsertPosition InsertBef) : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic, - SyncScope::System, /*IsElementwise=*/false, InsertBef) {} + SyncScope::System, InsertBef) {} LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, const LoadStoreInstProperties &Props, InsertPosition InsertBef) : LoadInst(Ty, Ptr, Name, Props.IsVolatile, Props.Alignment, Props.Ordering, - Props.SSID, /*IsElementwise=*/false, InsertBef) {} + Props.SSID, InsertBef) { + setElementwise(Props.IsElementwise); +} LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, Align Align, AtomicOrdering Order, SyncScope::ID SSID, InsertPosition InsertBef) - : LoadInst(Ty, Ptr, Name, isVolatile, Align, Order, SSID, - /*IsElementwise=*/false, InsertBef) {} - -LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, - Align Align, AtomicOrdering Order, SyncScope::ID SSID, - bool IsElementwise, InsertPosition InsertBef) : UnaryInstruction(Ty, Load, Ptr, InsertBef) { setVolatile(isVolatile); setAlignment(Align); setAtomic(Order, SSID); - setElementwise(IsElementwise); AssertOK(); setName(Name); } @@ -4460,9 +4455,7 @@ } LoadInst *LoadInst::cloneImpl() const { - return new LoadInst(getType(), getOperand(0), Twine(), isVolatile(), - getAlign(), getOrdering(), getSyncScopeID(), - isElementwise(), + return new LoadInst(getType(), getOperand(0), Twine(), getProperties(), /*InsertBefore=*/nullptr); }
diff --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp index f3753aa..48d461c 100644 --- a/llvm/unittests/IR/VerifierTest.cpp +++ b/llvm/unittests/IR/VerifierTest.cpp
@@ -521,7 +521,6 @@ new AtomicRMWInst(AtomicRMWInst::Add, Ptr, CV, Align(8), AtomicOrdering::SequentiallyConsistent, SyncScope::System, /*Elementwise=*/false, Entry); - ReturnInst::Create(C, Entry); std::string Error; @@ -530,6 +529,7 @@ EXPECT_TRUE( StringRef(Error).starts_with("atomicrmw add operand must have integer or " "fixed vector of integer type!")) + << Error; } TEST(VerifierTest, ElementwiseLoadNonAtomic) { @@ -543,9 +543,12 @@ Type *I32Ty = Type::getInt32Ty(C); Type *VecTy = FixedVectorType::get(I32Ty, 4); - new LoadInst(VecTy, Ptr, "", /*isVolatile=*/false, Align(4), - AtomicOrdering::NotAtomic, SyncScope::System, - /*IsElementwise=*/true, Entry); + new LoadInst(VecTy, Ptr, "", + LoadStoreInstProperties{/*IsVolatile=*/false, Align(4), + AtomicOrdering::NotAtomic, + SyncScope::System, + /*IsElementwise=*/true}, + Entry); ReturnInst::Create(C, Entry); std::string Error; @@ -566,9 +569,12 @@ Type *I32Ty = Type::getInt32Ty(C); - new LoadInst(I32Ty, Ptr, "", /*isVolatile=*/false, Align(4), - AtomicOrdering::Monotonic, SyncScope::System, - /*IsElementwise=*/true, Entry); + new LoadInst(I32Ty, Ptr, "", + LoadStoreInstProperties{/*IsVolatile=*/false, Align(4), + AtomicOrdering::Monotonic, + SyncScope::System, + /*IsElementwise=*/true}, + Entry); ReturnInst::Create(C, Entry); std::string Error; @@ -590,9 +596,12 @@ Type *I32Ty = Type::getInt32Ty(C); Type *VecTy = FixedVectorType::get(I32Ty, 5); - new LoadInst(VecTy, Ptr, "", /*isVolatile=*/false, Align(4), - AtomicOrdering::Monotonic, SyncScope::System, - /*IsElementwise=*/true, Entry); + new LoadInst(VecTy, Ptr, "", + LoadStoreInstProperties{/*IsVolatile=*/false, Align(4), + AtomicOrdering::Monotonic, + SyncScope::System, + /*IsElementwise=*/true}, + Entry); ReturnInst::Create(C, Entry); std::string Error;