diff --git a/llvm/lib/Target/AMDGPU/DSInstructions.td b/llvm/lib/Target/AMDGPU/DSInstructions.td --- a/llvm/lib/Target/AMDGPU/DSInstructions.td +++ b/llvm/lib/Target/AMDGPU/DSInstructions.td @@ -928,27 +928,28 @@ -class DSAtomicCmpXChg : GCNPat < +// Caution, the order of src and cmp is the *opposite* of the BUFFER_ATOMIC_CMPSWAP opcode. +class DSAtomicCmpXChgSwapped : GCNPat < (frag (DS1Addr1Offset i32:$ptr, i16:$offset), vt:$cmp, vt:$swap), (inst $ptr, getVregSrcForVT.ret:$cmp, getVregSrcForVT.ret:$swap, offset:$offset, (i1 gds)) >; -multiclass DSAtomicCmpXChg_mc { +multiclass DSAtomicCmpXChgSwapped_mc { let OtherPredicates = [LDSRequiresM0Init] in { - def : DSAtomicCmpXChg(frag#"_local_m0_ret_"#vt.Size)>; - def : DSAtomicCmpXChg(frag#"_local_m0_noret_"#vt.Size)>; + def : DSAtomicCmpXChgSwapped(frag#"_local_m0_ret_"#vt.Size)>; + def : DSAtomicCmpXChgSwapped(frag#"_local_m0_noret_"#vt.Size)>; } let OtherPredicates = [NotLDSRequiresM0Init] in { - def : DSAtomicCmpXChg(!cast(inst)#"_gfx9"), vt, - !cast(frag#"_local_ret_"#vt.Size)>; - def : DSAtomicCmpXChg(!cast(noRetInst)#"_gfx9"), vt, - !cast(frag#"_local_noret_"#vt.Size)>; + def : DSAtomicCmpXChgSwapped(!cast(inst)#"_gfx9"), vt, + !cast(frag#"_local_ret_"#vt.Size)>; + def : DSAtomicCmpXChgSwapped(!cast(noRetInst)#"_gfx9"), vt, + !cast(frag#"_local_noret_"#vt.Size)>; } - def : DSAtomicCmpXChg(frag#"_region_m0_ret_"#vt.Size), 1>; - def : DSAtomicCmpXChg(frag#"_region_m0_noret_"#vt.Size), 1>; + def : DSAtomicCmpXChgSwapped(frag#"_region_m0_ret_"#vt.Size), 1>; + def : DSAtomicCmpXChgSwapped(frag#"_region_m0_noret_"#vt.Size), 1>; } @@ -968,7 +969,7 @@ defm : DSAtomicRetNoRetPat_mc; defm : DSAtomicRetNoRetPat_mc; defm : DSAtomicRetNoRetPat_mc; -defm : DSAtomicCmpXChg_mc; +defm : DSAtomicCmpXChgSwapped_mc; let SubtargetPredicate = HasLDSFPAtomicAdd in { defm : DSAtomicRetNoRetPat_mc; @@ -990,7 +991,7 @@ defm : DSAtomicRetNoRetPat_mc; defm : DSAtomicRetNoRetPat_mc; -defm : DSAtomicCmpXChg_mc; +defm : DSAtomicCmpXChgSwapped_mc; let SubtargetPredicate = isGFX90APlus in { def : DSAtomicRetPat;