Skip to content

Commit a042983

Browse files
authored
Merge branch 'main' into p/clang-x86-fuchsia-safestack
2 parents 64b5018 + 10afda0 commit a042983

File tree

12 files changed

+961
-28
lines changed

12 files changed

+961
-28
lines changed

libc/utils/hdrgen/hdrgen/header.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,5 @@ def json_data(self):
241241
return {
242242
"name": self.name,
243243
"standards": self.standards,
244-
"includes": [
245-
str(file) for file in sorted({COMMON_HEADER} | self.includes())
246-
],
244+
"includes": sorted(str(file) for file in {COMMON_HEADER} | self.includes()),
247245
}

llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,26 @@ static void doAtomicBinOpExpansion(const RISCVInstrInfo *TII, MachineInstr &MI,
373373
.addReg(ScratchReg)
374374
.addImm(-1);
375375
break;
376+
case AtomicRMWInst::Max:
377+
BuildMI(LoopMBB, DL, TII->get(RISCV::MAX), ScratchReg)
378+
.addReg(DestReg)
379+
.addReg(IncrReg);
380+
break;
381+
case AtomicRMWInst::Min:
382+
BuildMI(LoopMBB, DL, TII->get(RISCV::MIN), ScratchReg)
383+
.addReg(DestReg)
384+
.addReg(IncrReg);
385+
break;
386+
case AtomicRMWInst::UMax:
387+
BuildMI(LoopMBB, DL, TII->get(RISCV::MAXU), ScratchReg)
388+
.addReg(DestReg)
389+
.addReg(IncrReg);
390+
break;
391+
case AtomicRMWInst::UMin:
392+
BuildMI(LoopMBB, DL, TII->get(RISCV::MINU), ScratchReg)
393+
.addReg(DestReg)
394+
.addReg(IncrReg);
395+
break;
376396
}
377397
BuildMI(LoopMBB, DL, TII->get(getSCForRMW(Ordering, Width, STI)), ScratchReg)
378398
.addReg(ScratchReg)
@@ -682,6 +702,9 @@ bool RISCVExpandAtomicPseudo::expandAtomicMinMaxOp(
682702
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
683703
AtomicRMWInst::BinOp BinOp, bool IsMasked, int Width,
684704
MachineBasicBlock::iterator &NextMBBI) {
705+
// Using MIN(U)/MAX(U) is preferrable if permitted
706+
if (STI->hasPermissiveZalrsc() && STI->hasStdExtZbb() && !IsMasked)
707+
return expandAtomicBinOp(MBB, MBBI, BinOp, IsMasked, Width, NextMBBI);
685708

686709
MachineInstr &MI = *MBBI;
687710
DebugLoc DL = MI.getDebugLoc();

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,25 @@ def FeatureForcedAtomics : SubtargetFeature<
19061906
def HasAtomicLdSt
19071907
: Predicate<"Subtarget->hasStdExtZalrsc() || Subtarget->hasForcedAtomics()">;
19081908

1909+
// The RISC-V Unprivileged Architecture - ISA Volume 1 (Version: 20250508)
1910+
// [https://docs.riscv.org/reference/isa/_attachments/riscv-unprivileged.pdf]
1911+
// in section 13.3. Eventual Success of Store-Conditional Instructions, defines
1912+
// _constrained_ LR/SC loops:
1913+
// The dynamic code executed between the LR and SC instructions can only
1914+
// contain instructions from the base ''I'' instruction set, excluding loads,
1915+
// stores, backward jumps, taken backward branches, JALR, FENCE, and SYSTEM
1916+
// instructions. Compressed forms of the aforementioned ''I'' instructions in
1917+
// the Zca and Zcb extensions are also permitted.
1918+
// LR/SC loops that do not adhere to the above are _unconstrained_ LR/SC loops,
1919+
// and success is implementation specific. For implementations which know that
1920+
// non-base instructions (such as the ''B'' extension) will not violate any
1921+
// forward progress guarantees, using these instructions to reduce the LR/SC
1922+
// sequence length is desirable.
1923+
def FeaturePermissiveZalrsc
1924+
: SubtargetFeature<
1925+
"permissive-zalrsc", "HasPermissiveZalrsc", "true",
1926+
"Implementation permits non-base instructions between LR/SC pairs">;
1927+
19091928
def FeatureTaggedGlobals : SubtargetFeature<"tagged-globals",
19101929
"AllowTaggedGlobals",
19111930
"true", "Use an instruction sequence for taking the address of a global "

0 commit comments

Comments
 (0)