Skip to content

Commit 2dccfa1

Browse files
Fix test when target memory locations are combined
1 parent 1987000 commit 2dccfa1

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

llvm/include/llvm/Support/ModRef.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,30 @@ template <typename LocationEnum> class MemoryEffectsBase {
157157
return MemoryEffectsBase(Location::Other, MR);
158158
}
159159

160+
/// Create MemoryEffectsBase that can only read inaccessible memory.
161+
static MemoryEffectsBase
162+
inaccessibleReadMemOnly(Location Loc = Location::InaccessibleMem) {
163+
return MemoryEffectsBase(Loc, ModRefInfo::Ref);
164+
}
165+
166+
/// Create MemoryEffectsBase that can only write inaccessible memory.
167+
static MemoryEffectsBase
168+
inaccessibleWriteMemOnly(Location Loc = Location::InaccessibleMem) {
169+
return MemoryEffectsBase(Loc, ModRefInfo::Mod);
170+
}
171+
172+
/// Checks if only target-specific memory locations are set.
173+
/// Ignores standard locations like ArgMem or InaccessibleMem.
174+
/// Needed because `Data` may be non-zero by default unless explicitly
175+
/// cleared.
176+
bool onlyAccessTargetMemoryLocation() {
177+
return getWithoutLoc(static_cast<IRMemLocation>(
178+
llvm::InaccessibleTargetMemLocation::AARCH64_FPMR))
179+
.getWithoutLoc(static_cast<IRMemLocation>(
180+
llvm::InaccessibleTargetMemLocation::AARCH64_ZA))
181+
.doesNotAccessMemory();
182+
}
183+
160184
/// Create MemoryEffectsBase that can only access inaccessible or argument
161185
/// memory.
162186
static MemoryEffectsBase

llvm/test/TableGen/intrinsic-attrs-fp8.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def int_aarch64_get_fpmr_set_za : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [In
2424
// CHECK-NEXT: Attribute::get(C, Attribute::NoSync),
2525
// CHECK-NEXT: Attribute::get(C, Attribute::NoFree),
2626
// CHECK-NEXT: Attribute::get(C, Attribute::WillReturn),
27-
// CHECK-NEXT: // ArgMem: ModRef, InaccessibleMem: ModRef, ErrnoMem: ModRef, AARCH64_FPMR: Ref, AARCH64_ZA: Mod, Other: ModRef
28-
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(3711)),
27+
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, AARCH64_FPMR: Ref, AARCH64_ZA: Mod, Other: NoModRef
28+
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(576)),
2929
// CHECK-NEXT: });
3030
// CHECK-NEXT: case 1:
3131
// CHECK-NEXT: return AttributeSet::get(C, {
@@ -34,8 +34,8 @@ def int_aarch64_get_fpmr_set_za : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [In
3434
// CHECK-NEXT: Attribute::get(C, Attribute::NoSync),
3535
// CHECK-NEXT: Attribute::get(C, Attribute::NoFree),
3636
// CHECK-NEXT: Attribute::get(C, Attribute::WillReturn),
37-
// CHECK-NEXT: // ArgMem: ModRef, InaccessibleMem: ModRef, ErrnoMem: ModRef, AARCH64_FPMR: ModRef, AARCH64_ZA: Ref, Other: ModRef
38-
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(3583)),
37+
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, AARCH64_FPMR: NoModRef, AARCH64_ZA: Ref, Other: NoModRef
38+
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(256)),
3939
// CHECK-NEXT: });
4040
// CHECK-NEXT: case 2:
4141
// CHECK-NEXT: return AttributeSet::get(C, {
@@ -44,8 +44,8 @@ def int_aarch64_get_fpmr_set_za : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [In
4444
// CHECK-NEXT: Attribute::get(C, Attribute::NoSync),
4545
// CHECK-NEXT: Attribute::get(C, Attribute::NoFree),
4646
// CHECK-NEXT: Attribute::get(C, Attribute::WillReturn),
47-
// CHECK-NEXT: // ArgMem: ModRef, InaccessibleMem: ModRef, ErrnoMem: ModRef, AARCH64_FPMR: Mod, AARCH64_ZA: ModRef, Other: ModRef
48-
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(4031)),
47+
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, AARCH64_FPMR: Mod, AARCH64_ZA: NoModRef, Other: NoModRef
48+
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(128)),
4949

5050
// CHECK: static constexpr uint16_t IntrinsicsToAttributesMap[] = {
5151
// CHECK-NEXT: 0 << 8 | 0, // llvm.aarch64.get.fpmr.set.za

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,16 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
376376
ME &= MemoryEffects::inaccessibleMemOnly();
377377
else if (R->isSubClassOf("IntrInaccessibleReadMemOnly")) {
378378
llvm::IRMemLocation Loc = R->getLocationTypeAsInt("Loc");
379-
ME = ME.getWithModRef(Loc, ModRefInfo::Ref);
379+
if (ME.onlyAccessTargetMemoryLocation())
380+
ME = ME.getWithModRef(Loc, ModRefInfo::Ref);
381+
else
382+
ME &= MemoryEffects::inaccessibleReadMemOnly(Loc);
380383
} else if (R->isSubClassOf("IntrInaccessibleWriteMemOnly")) {
381384
llvm::IRMemLocation Loc = R->getLocationTypeAsInt("Loc");
382-
ME = ME.getWithModRef(Loc, ModRefInfo::Mod);
385+
if (ME.onlyAccessTargetMemoryLocation())
386+
ME = ME.getWithModRef(Loc, ModRefInfo::Mod);
387+
else
388+
ME &= MemoryEffects::inaccessibleWriteMemOnly(Loc);
383389
} else if (R->getName() == "IntrInaccessibleMemOrArgMemOnly")
384390
ME &= MemoryEffects::inaccessibleOrArgMemOnly();
385391
else if (R->getName() == "Commutative")

0 commit comments

Comments
 (0)