[llvm] Ak Flavoured LR/SC Count (PR #177641)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 23 10:25:25 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Ali Kamran (ilanarmak03)
<details>
<summary>Changes</summary>
Counts every flavour of LR or SC and records it into a mapping of Func -> Basic block -> Instruction flavour -> count.
Sample output:
```
Number of LR/SC instruction: 2
{
"functions": {
"": {
"basic_blocks": [
{
"bb_index": 0,
"bb_total_lrsc_occurrences": 0,
"flavors": {},
"mbb_number": -1
},
{
"bb_index": 1,
"bb_total_lrsc_occurrences": 1,
"flavors": {
"LR_W_AQRL": 1
},
"mbb_number": -1
},
{
"bb_index": 2,
"bb_total_lrsc_occurrences": 1,
"flavors": {
"SC_W_RL": 1
},
"mbb_number": 0
},
{
"bb_index": 3,
"bb_total_lrsc_occurrences": 0,
```
---
Full diff: https://github.com/llvm/llvm-project/pull/177641.diff
9 Files Affected:
- (modified) llvm/lib/Target/RISCV/CMakeLists.txt (+1)
- (modified) llvm/lib/Target/RISCV/RISCV.h (+3)
- (added) llvm/lib/Target/RISCV/RISCVCountLRSC.cpp (+317)
- (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+4)
- (modified) llvm/utils/gn/secondary/llvm/lib/Target/RISCV/BUILD.gn (+1)
- (added) tests/lrsc_pass.log (+52)
- (added) tests/one_lrsc.c (+13)
- (added) tests/one_lrsc.ll (+23)
- (added) tests/one_lrsc.s (+37)
``````````diff
diff --git a/llvm/lib/Target/RISCV/CMakeLists.txt b/llvm/lib/Target/RISCV/CMakeLists.txt
index f8cf71ea077d6..f9fee2b09c3b6 100644
--- a/llvm/lib/Target/RISCV/CMakeLists.txt
+++ b/llvm/lib/Target/RISCV/CMakeLists.txt
@@ -35,6 +35,7 @@ add_llvm_target(RISCVCodeGen
RISCVCallingConv.cpp
RISCVCodeGenPrepare.cpp
RISCVConstantPoolValue.cpp
+ RISCVCountLRSC.cpp
RISCVDeadRegisterDefinitions.cpp
RISCVExpandAtomicPseudoInsts.cpp
RISCVExpandPseudoInsts.cpp
diff --git a/llvm/lib/Target/RISCV/RISCV.h b/llvm/lib/Target/RISCV/RISCV.h
index 048db205e2289..6820af839d6b7 100644
--- a/llvm/lib/Target/RISCV/RISCV.h
+++ b/llvm/lib/Target/RISCV/RISCV.h
@@ -37,6 +37,9 @@ class RISCVCodeGenPreparePass : public PassInfoMixin<RISCVCodeGenPreparePass> {
FunctionPass *createRISCVCodeGenPrepareLegacyPass();
void initializeRISCVCodeGenPrepareLegacyPassPass(PassRegistry &);
+FunctionPass *createRISCVCountLRSCPass();
+void initializeRISCVCountLRSCPass(PassRegistry &);
+
FunctionPass *createRISCVDeadRegisterDefinitionsPass();
void initializeRISCVDeadRegisterDefinitionsPass(PassRegistry &);
diff --git a/llvm/lib/Target/RISCV/RISCVCountLRSC.cpp b/llvm/lib/Target/RISCV/RISCVCountLRSC.cpp
new file mode 100644
index 0000000000000..526aaaf5e0094
--- /dev/null
+++ b/llvm/lib/Target/RISCV/RISCVCountLRSC.cpp
@@ -0,0 +1,317 @@
+//===-- RISCVCountLRSC.cpp - Count LR/SC instruction pairs -----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains a pass that counts the # of the LR/SC pairs. This pass
+// should run just before code generation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RISCV.h"
+#include "RISCVInstrInfo.h"
+#include "RISCVTargetMachine.h"
+// Added includes:
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/JSON.h"
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+using namespace llvm;
+
+#define RISCV_COUNT_LR_SC_NAME "RISC-V count LR/SC instruction pairs"
+#define DEBUG_TYPE "riscvcntlrsc"
+
+namespace {
+
+class RISCVCountLRSC : public MachineFunctionPass {
+public:
+ const RISCVSubtarget *STI;
+ const RISCVInstrInfo *TII;
+
+ static char ID;
+
+ RISCVCountLRSC() : MachineFunctionPass(ID) {}
+ ~RISCVCountLRSC();
+
+ bool runOnMachineFunction(MachineFunction &MF) override;
+
+ StringRef getPassName() const override { return RISCV_COUNT_LR_SC_NAME; }
+
+ void print(raw_ostream &OS) const;
+
+private:
+ unsigned countLRSC(MachineBasicBlock &MBB,
+ MachineFunction &MF); // added &MF as a param
+ unsigned totalCount = 0;
+
+ // How it used to be:
+ /* std::unordered_map<const MachineFunction*, std::unordered_map<const
+ MachineBasicBlock*, std::unordered_map< uint16_t, int>>>
+ basicBlocksFlavourCounts; //mapping of MF address -> BB address -> (mapping
+ of opcode[uint16_t] -> count of LR/SC occurrences) std::unordered_map<const
+ MachineFunction*, std::unordered_map<const MachineBasicBlock* , int>>
+ basicBlocksCounts;// mapping of MF address -> BB address -> count of LR/SC
+ occurrences in the BB std::unordered_map<const MachineFunction*, int>
+ functionCounts;// mapping of MF address -> count of LR/SC occurrences in
+ the function
+ */
+
+ // Made a struct that gathers all of the umaps together
+ struct LRSCCounts {
+ using MFKey = const MachineFunction *;
+ using BBKey = const MachineBasicBlock *;
+ using OpKey = std::string;
+
+ using BBList = std::vector<BBKey>;
+ using MFToBBListMap = std::unordered_map<MFKey, BBList>;
+
+ // MF -> list of BB pointers in MF iteration order
+ MFToBBListMap basicBlockOrder;
+
+ using FlavourMap = std::unordered_map<OpKey, int>;
+ using BBToFlavourMap = std::unordered_map<BBKey, FlavourMap>;
+ using MFToBBFlavourMap = std::unordered_map<MFKey, BBToFlavourMap>;
+
+ using BBCountMap = std::unordered_map<BBKey, int>;
+ using MFToBBCountMap = std::unordered_map<MFKey, BBCountMap>;
+
+ using MFCountMap = std::unordered_map<MFKey, int>;
+
+ // MF -> BB -> (opcode -> count)
+ MFToBBFlavourMap basicBlocksFlavourCounts;
+
+ // MF -> BB -> total LR/SC occurrences (or pairs, depending on your
+ // definition)
+ MFToBBCountMap basicBlocksCounts;
+
+ // MF -> total LR/SC occurrences (or pairs)
+ MFCountMap functionCounts;
+
+ void clear() {
+ basicBlockOrder.clear();
+ basicBlocksFlavourCounts.clear();
+ basicBlocksCounts.clear();
+ functionCounts.clear();
+ }
+ llvm::json::Value toJSON() const {
+ llvm::json::Object Root;
+ llvm::json::Object FuncMap; // function-name -> { totals, basic_blocks }
+
+ for (const auto &FO : basicBlockOrder) {
+ const MachineFunction *MF = FO.first;
+ const auto &Order = FO.second;
+
+ std::string Name = MF ? MF->getName().str() : "<null>";
+
+ int FuncTotal = 0;
+ if (auto ItFT = functionCounts.find(MF); ItFT != functionCounts.end())
+ FuncTotal = ItFT->second;
+
+ llvm::json::Array Blocks;
+
+ auto ItBBTotals = basicBlocksCounts.find(MF);
+ auto ItBBFlavors = basicBlocksFlavourCounts.find(MF);
+
+ for (size_t i = 0; i < Order.size(); ++i) {
+ const MachineBasicBlock *MBB = Order[i];
+
+ llvm::json::Object BBObj;
+ BBObj["bb_index"] = static_cast<int64_t>(i);
+ BBObj["mbb_number"] = MBB ? static_cast<int64_t>(MBB->getNumber()) : -1;
+
+ int BBTotal = 0;
+ if (ItBBTotals != basicBlocksCounts.end() && MBB) {
+ auto It = ItBBTotals->second.find(MBB);
+ if (It != ItBBTotals->second.end())
+ BBTotal = It->second;
+ }
+ BBObj["bb_total_lrsc_occurrences"] = BBTotal;
+
+ llvm::json::Object FlavorsObj;
+ if (ItBBFlavors != basicBlocksFlavourCounts.end() && MBB) {
+ auto ItF = ItBBFlavors->second.find(MBB);
+ if (ItF != ItBBFlavors->second.end()) {
+ for (const auto &OP : ItF->second)
+ FlavorsObj.try_emplace(OP.first, OP.second);
+ }
+ }
+
+ BBObj["flavors"] = std::move(FlavorsObj);
+ Blocks.push_back(std::move(BBObj));
+ }
+
+ llvm::json::Object FObj;
+ FObj["total_lrsc_occurrences"] = FuncTotal;
+ FObj["basic_blocks"] = std::move(Blocks);
+
+ FuncMap.try_emplace(std::move(Name), std::move(FObj));
+ }
+
+ Root["functions"] = std::move(FuncMap);
+ return llvm::json::Value(std::move(Root));
+}
+ };
+ LRSCCounts Counts;
+};
+
+} // end anonymous namespace
+
+char RISCVCountLRSC::ID = 0;
+INITIALIZE_PASS(RISCVCountLRSC, "riscv-count-lr-sc", RISCV_COUNT_LR_SC_NAME,
+ false, false)
+
+RISCVCountLRSC::~RISCVCountLRSC() { print(dbgs()); }
+
+FunctionPass *llvm::createRISCVCountLRSCPass() { return new RISCVCountLRSC(); }
+
+bool RISCVCountLRSC::runOnMachineFunction(MachineFunction &MF) {
+
+
+
+ Counts.basicBlockOrder[&MF]
+ .clear(); // Clear stored BB iteration order for this MF (ensures bb_index is 0..N-1 for this function).
+ auto &Order = Counts.basicBlockOrder[&MF]; // Alias per-function BB order vector (MF -> [BB pointers in traversal order]) for stable bb_index.
+
+ STI =
+ &MF.getSubtarget<RISCVSubtarget>(); // Sub Target Instruction CPU features
+ // :extensions, scheduling model, etc.
+ TII = STI->getInstrInfo(); // Instruction Info Table : opcodes, pseudo
+ // expansion info, etc.
+ unsigned bbCount = 0;
+ unsigned mfCount = 0;
+
+ // traverse through the machine basic blocks and
+ // get the running count of detected LR/SC pairs [Ali]: We are not counting
+ // pairs are we?
+ for (auto &MBB : MF) {
+ Order.push_back(&MBB); // Record BB pointer in traversal order so JSON can emit all BBs (including zero-count) with a stable bb_index.
+
+
+ bbCount = countLRSC(MBB, MF); // # LR/SC occurrences in a BB
+
+ Counts.basicBlocksCounts[&MF].try_emplace(&MBB, 0); // Ensure MF->BB entry exists even when this BB has zero LR/SC occurrences.
+ Counts.basicBlocksCounts[&MF][&MBB] +=
+ bbCount; // # LR/SC occurrences in a BB added to the mapping of MF -> BB
+ // -> count
+ mfCount += bbCount; // # LR/SC occurrences in a BB added to the total number
+ // of instructions for the fucntion
+ }
+ totalCount += mfCount; // # LR/SC occurrences in a BB added to the total
+ // number of instructions for the whole compilation
+ Counts.functionCounts[&MF] += mfCount; // # LR/SC occurrences in a BB added to
+ // the mapping of MF -> count
+ return false; // returns false right? we are not modifying the code during
+ // compilation
+}
+
+unsigned
+RISCVCountLRSC::countLRSC(MachineBasicBlock &MBB,
+ MachineFunction &MF) { // added &MF as a param
+
+ MachineBasicBlock::iterator MBBI = MBB.begin();
+ MachineBasicBlock::iterator E = MBB.end();
+
+ // iterates over each MBBI and compares the opcode to every flavour of LR/SC
+ // instructions and adds to the count of each flavour of each instruction in
+ // an unordered mapping
+
+ unsigned total = 0;
+ uint16_t opc = 0;
+ while (MBBI != E) {
+
+ opc = MBBI->getOpcode();
+ switch (opc) {
+ // LR flavours
+ case RISCV::LR_W:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_W"]++;
+ total++;
+ break;
+ case RISCV::LR_D:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_D"]++;
+ total++;
+ break;
+ case RISCV::LR_D_AQ:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_D_AQ"]++;
+ total++;
+ break;
+ case RISCV::LR_W_AQ:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_W_AQ"]++;
+ total++;
+ break;
+ case RISCV::LR_D_RL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_D_RL"]++;
+ total++;
+ break;
+ case RISCV::LR_W_RL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_W_RL"]++;
+ total++;
+ break;
+ case RISCV::LR_D_AQRL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_D_AQRL"]++;
+ total++;
+ break;
+ case RISCV::LR_W_AQRL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["LR_W_AQRL"]++;
+ total++;
+ break;
+
+ // SC flavours
+ case RISCV::SC_W:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_W"]++;
+ total++;
+ break;
+ case RISCV::SC_D:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_D"]++;
+ total++;
+ break;
+ case RISCV::SC_D_AQ:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_D_AQ"]++;
+ total++;
+ break;
+ case RISCV::SC_W_AQ:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_W_AQ"]++;
+ total++;
+ break;
+ case RISCV::SC_D_RL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_D_RL"]++;
+ total++;
+ break;
+ case RISCV::SC_W_RL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_W_RL"]++;
+ total++;
+ break;
+ case RISCV::SC_D_AQRL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_D_AQRL"]++;
+ total++;
+ break;
+ case RISCV::SC_W_AQRL:
+ Counts.basicBlocksFlavourCounts[&MF][&MBB]["SC_W_AQRL"]++;
+ total++;
+ break;
+
+ default:
+ break;
+ }
+
+ MBBI++;
+ }
+ return total;
+}
+
+void RISCVCountLRSC::print(raw_ostream &OS) const {
+ OS << "Number of LR/SC instruction: " << totalCount << "\n";
+
+ llvm::json::Value J = Counts.toJSON();
+
+ // Pretty print with indent=2
+ OS << llvm::formatv("{0:2}", J) << "\n";
+}
diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 52dc38564059c..378845525647a 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -146,6 +146,7 @@ extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
initializeRISCVRedundantCopyEliminationPass(*PR);
initializeRISCVAsmPrinterPass(*PR);
initializeRISCVPromoteConstantPass(*PR);
+ initializeRISCVCountLRSCPass(*PR);
}
static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
@@ -587,6 +588,9 @@ void RISCVPassConfig::addPreEmitPass2() {
if (EnableCFIInstrInserter)
addPass(createCFIInstrInserter());
+
+ // add pass to count LR/SC instruction pairs...
+ addPass(createRISCVCountLRSCPass());
}
void RISCVPassConfig::addMachineSSAOptimization() {
diff --git a/llvm/utils/gn/secondary/llvm/lib/Target/RISCV/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Target/RISCV/BUILD.gn
index e54797e188a11..d1549be81aeaf 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Target/RISCV/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/Target/RISCV/BUILD.gn
@@ -128,6 +128,7 @@ static_library("LLVMRISCVCodeGen") {
"RISCVCallingConv.cpp",
"RISCVCodeGenPrepare.cpp",
"RISCVConstantPoolValue.cpp",
+ "RISCVCountLRSC.cpp",
"RISCVDeadRegisterDefinitions.cpp",
"RISCVExpandAtomicPseudoInsts.cpp",
"RISCVExpandPseudoInsts.cpp",
diff --git a/tests/lrsc_pass.log b/tests/lrsc_pass.log
new file mode 100644
index 0000000000000..c0492b16dd10f
--- /dev/null
+++ b/tests/lrsc_pass.log
@@ -0,0 +1,52 @@
+'-experimental-zacas' is not a recognized feature for this target (ignoring feature)
+'-experimental-zcmop' is not a recognized feature for this target (ignoring feature)
+'-experimental-zfbfmin' is not a recognized feature for this target (ignoring feature)
+'-experimental-zimop' is not a recognized feature for this target (ignoring feature)
+'-experimental-ztso' is not a recognized feature for this target (ignoring feature)
+'-experimental-zvfbfmin' is not a recognized feature for this target (ignoring feature)
+'-experimental-zvfbfwma' is not a recognized feature for this target (ignoring feature)
+'-experimental-zacas' is not a recognized feature for this target (ignoring feature)
+'-experimental-zcmop' is not a recognized feature for this target (ignoring feature)
+'-experimental-zfbfmin' is not a recognized feature for this target (ignoring feature)
+'-experimental-zimop' is not a recognized feature for this target (ignoring feature)
+'-experimental-ztso' is not a recognized feature for this target (ignoring feature)
+'-experimental-zvfbfmin' is not a recognized feature for this target (ignoring feature)
+'-experimental-zvfbfwma' is not a recognized feature for this target (ignoring feature)
+Number of LR/SC instruction: 2
+{
+ "functions": {
+ "": {
+ "basic_blocks": [
+ {
+ "bb_index": 0,
+ "bb_total_lrsc_occurrences": 0,
+ "flavors": {},
+ "mbb_number": -1
+ },
+ {
+ "bb_index": 1,
+ "bb_total_lrsc_occurrences": 1,
+ "flavors": {
+ "LR_W_AQRL": 1
+ },
+ "mbb_number": -1
+ },
+ {
+ "bb_index": 2,
+ "bb_total_lrsc_occurrences": 1,
+ "flavors": {
+ "SC_W_RL": 1
+ },
+ "mbb_number": 0
+ },
+ {
+ "bb_index": 3,
+ "bb_total_lrsc_occurrences": 0,
+ "flavors": {},
+ "mbb_number": -1
+ }
+ ],
+ "total_lrsc_occurrences": 2
+ }
+ }
+}
diff --git a/tests/one_lrsc.c b/tests/one_lrsc.c
new file mode 100644
index 0000000000000..7d95ca6112cc9
--- /dev/null
+++ b/tests/one_lrsc.c
@@ -0,0 +1,13 @@
+#include <stdint.h>
+#include <stdbool.h>
+
+volatile uint32_t g = 0;
+
+bool cas_u32(uint32_t expected, uint32_t desired) {
+ // Strong CAS usually lowers to an LR/SC loop on RISC-V
+ return __atomic_compare_exchange_n(&g, &expected, desired,
+ /*weak=*/false,
+ __ATOMIC_SEQ_CST,
+ __ATOMIC_SEQ_CST);
+}
+
diff --git a/tests/one_lrsc.ll b/tests/one_lrsc.ll
new file mode 100644
index 0000000000000..b928c76711c25
--- /dev/null
+++ b/tests/one_lrsc.ll
@@ -0,0 +1,23 @@
+; ModuleID = 'test/one_lrsc.c'
+source_filename = "test/one_lrsc.c"
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+target triple = "riscv64-unknown-unknown-elf"
+
+ at g = dso_local global i32 0, align 4
+
+; Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(readwrite, argmem: none)
+define dso_local zeroext i1 @cas_u32(i32 noundef signext %0, i32 noundef signext %1) local_unnamed_addr #0 {
+ %3 = cmpxchg volatile ptr @g, i32 %0, i32 %1 seq_cst seq_cst, align 4
+ %4 = extractvalue { i32, i1 } %3, 1
+ ret i1 %4
+}
+
+attributes #0 = { mustprogress nofree norecurse nounwind willreturn memory(readwrite, argmem: none) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic-rv64" "target-features"="+64bit,+a,+c,+m,+relax,-d,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-f,-h,-smaia,-smepmp,-ssaia,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b" }
+
+!llvm.module.flags = !{!0, !1, !2}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 1, !"target-abi", !"lp64"}
+!2 = !{i32 8, !"SmallDataLimit", i32 8}
+!3 = !{!"Ubuntu clang version 18.1.3 (1ubuntu1)"}
diff --git a/tests/one_lrsc.s b/tests/one_lrsc.s
new file mode 100644
index 0000000000000..c04c990a16a1b
--- /dev/null
+++ b/tests/one_lrsc.s
@@ -0,0 +1,37 @@
+ .attribute 4, 16
+ .attribute 5, "rv64i2p1"
+ .file "one_lrsc.c"
+ .option push
+ .option arch, +a, +zaamo, +zalrsc
+ .text
+ .globl cas_u32 # -- Begin function cas_u32
+ .p2align 2
+ .type cas_u32, at function
+cas_u32: # @cas_u32
+# %bb.0:
+ lui a2, %hi(g)
+ addi a2, a2, %lo(g)
+.LBB0_1: # =>This Inner Loop Header: Depth=1
+ lr.w.aqrl a3, (a2)
+ bne a3, a0, .LBB0_3
+# %bb.2: # in Loop: Header=BB0_1 Depth=1
+ sc.w.rl a4, a1, (a2)
+ bnez a4, .LBB0_1
+.LBB0_3:
+ xor a0, a3, a0
+ seqz a0, a0
+ ret
+.Lfunc_end0:
+ .size cas_u32, .Lfunc_end0-cas_u32
+ # -- End function
+ .option pop
+ .type g, at object # @g
+ .section .sbss,"aw", at nobits
+ .globl g
+ .p2align 2, 0x0
+g:
+ .word 0 # 0x0
+ .size g, 4
+
+ .ident "Ubuntu clang version 18.1.3 (1ubuntu1)"
+ .section ".note.GNU-stack","", at progbits
``````````
</details>
https://github.com/llvm/llvm-project/pull/177641
More information about the llvm-commits
mailing list