[llvm] [SPIRV] Audit `select` Result in SPIRVInstructionSelector (PR #115193)
Greg Roth via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 11 08:56:00 PST 2024
================
@@ -1229,17 +1244,26 @@ bool SPIRVInstructionSelector::selectAtomicCmpXchg(Register ResVReg,
const MachineMemOperand *MemOp = *I.memoperands_begin();
unsigned Scope = static_cast<uint32_t>(getMemScope(
GR.CurMF->getFunction().getContext(), MemOp->getSyncScopeID()));
- ScopeReg = buildI32Constant(Scope, I);
+ auto ScopeConstant = buildI32Constant(Scope, I);
+ ScopeReg = ScopeConstant.first;
+ Result &= ScopeConstant.second;
unsigned ScSem = static_cast<uint32_t>(
getMemSemanticsForStorageClass(GR.getPointerStorageClass(Ptr)));
AtomicOrdering AO = MemOp->getSuccessOrdering();
unsigned MemSemEq = static_cast<uint32_t>(getMemSemantics(AO)) | ScSem;
- MemSemEqReg = buildI32Constant(MemSemEq, I);
+ auto MemSemEqConstant = buildI32Constant(MemSemEq, I);
+ MemSemEqReg = MemSemEqConstant.first;
+ Result &= MemSemEqConstant.second;
AtomicOrdering FO = MemOp->getFailureOrdering();
unsigned MemSemNeq = static_cast<uint32_t>(getMemSemantics(FO)) | ScSem;
- MemSemNeqReg =
- MemSemEq == MemSemNeq ? MemSemEqReg : buildI32Constant(MemSemNeq, I);
+ if (MemSemEq == MemSemNeq)
+ MemSemNeqReg = MemSemEqReg;
+ else {
+ auto MemSemNeqConstant = buildI32Constant(MemSemEq, I);
+ MemSemNeqReg = MemSemNeqConstant.first;
+ Result &= MemSemNeqConstant.second;
----------------
pow2clk wrote:
I'm not going to insist on it, but just FYI, you could have made `buildI32Constant` return `Register()` in the failing case, which could be identified by checking `Register.isValid()` rather than returning an additional bool. It might have made this a little more elegant, but I'm not sure about that and it's entirely a non-functional change, so I'll happily defer to the implementer here.
https://github.com/llvm/llvm-project/pull/115193
More information about the llvm-commits
mailing list