[SystemZ] Do not use LOC(G) for volatile loads

It is not safe to use LOAD ON CONDITION to implement access to a memory
location marked "volatile", since the architecture leaves it unspecified
whether or not an access happens if the condition is false.

The current code already appears to care about that:
  def LOC  : CondUnaryRSY<"loc",  0xEBF2, nonvolatile_load, GR32, 4>;

Unfortunately, that "nonvolatile_load" operator is simply ignored
by the CondUnaryRSY class, and there was no test to catch it.

llvm-svn: 285077
This commit is contained in:
Ulrich Weigand 2016-10-25 15:39:15 +00:00
parent 91cc4a6503
commit 7bdb485e18
3 changed files with 29 additions and 1 deletions

View File

@ -1665,7 +1665,7 @@ class CondUnaryRSY<string mnemonic, bits<16> opcode,
(ins cls:$R1src, mode:$BD2, cond4:$valid, cond4:$R3), (ins cls:$R1src, mode:$BD2, cond4:$valid, cond4:$R3),
mnemonic#"$R3\t$R1, $BD2", mnemonic#"$R3\t$R1, $BD2",
[(set cls:$R1, [(set cls:$R1,
(z_select_ccmask (load bdaddr20only:$BD2), cls:$R1src, (z_select_ccmask (operator bdaddr20only:$BD2), cls:$R1src,
cond4:$valid, cond4:$R3))]>, cond4:$valid, cond4:$R3))]>,
Requires<[FeatureLoadStoreOnCond]> { Requires<[FeatureLoadStoreOnCond]> {
let Constraints = "$R1 = $R1src"; let Constraints = "$R1 = $R1src";

View File

@ -128,3 +128,17 @@ exit:
%res = phi i32 [ %easy, %entry ], [ %other, %load ] %res = phi i32 [ %easy, %entry ], [ %other, %load ]
ret i32 %res ret i32 %res
} }
; Test that volatile loads do not use LOC, since if the condition is false,
; it is unspecified whether or not the load happens. LOCR is fine though.
define i32 @f10(i32 %easy, i32 *%ptr, i32 %limit) {
; CHECK-LABEL: f10:
; CHECK: l {{%r[0-9]*}}, 0(%r3)
; CHECK: locr
; CHECK: br %r14
%cond = icmp ult i32 %limit, 42
%other = load volatile i32, i32 *%ptr
%res = select i1 %cond, i32 %easy, i32 %other
ret i32 %res
}

View File

@ -128,3 +128,17 @@ exit:
%res = phi i64 [ %easy, %entry ], [ %other, %load ] %res = phi i64 [ %easy, %entry ], [ %other, %load ]
ret i64 %res ret i64 %res
} }
; Test that volatile loads do not use LOCG, since if the condition is false,
; it is unspecified whether or not the load happens. LOCGR is fine though.
define i64 @f10(i64 %easy, i64 *%ptr, i64 %limit) {
; CHECK-LABEL: f10:
; CHECK: lg {{%r[0-9]*}}, 0(%r3)
; CHECK: locgr
; CHECK: br %r14
%cond = icmp ult i64 %limit, 42
%other = load volatile i64, i64 *%ptr
%res = select i1 %cond, i64 %easy, i64 %other
ret i64 %res
}