Skip to content

Commit fcd7b8d

Browse files
authored
[X86] Add baseline test for X86 conditional load/store optimization bug (llvm#163354)
This PR adds a baseline test that exposes a bug in the current `combineX86CloadCstore` optimization. The generated assembly demonstrates incorrect behavior when the optimization is applied without proper constraints. Without any assumptions about `X` this transformation is only valid when `Y` is a non zero power of two/single-bit mask. ```cpp // res, flags2 = sub 0, (and (xor X, -1), Y) // cload/cstore ..., cond_ne, flag2 // -> // res, flags2 = sub 0, (and X, Y) // cload/cstore ..., cond_e, flag2 ``` In the provided test case, the value in `%al` is unknown at compile time. If `%al` contains `0`, the optimization cannot be applied, because `(and (xor X, -1), 0)` is not equal to `(and X, 0)`. Fix: llvm#163353
1 parent 7275256 commit fcd7b8d

File tree

1 file changed

+17
-0
lines changed
  • llvm/test/CodeGen/X86/apx

1 file changed

+17
-0
lines changed

llvm/test/CodeGen/X86/apx/cf.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,23 @@ entry:
230230
ret void
231231
}
232232

233+
define void @and_cond(i32 %a, i1 %b) {
234+
; CHECK-LABEL: and_cond:
235+
; CHECK: # %bb.0:
236+
; CHECK-NEXT: testl %edi, %edi
237+
; CHECK-NEXT: setg %al
238+
; CHECK-NEXT: xorl %ecx, %ecx
239+
; CHECK-NEXT: testb %al, %sil
240+
; CHECK-NEXT: cfcmovel %ecx, 0
241+
; CHECK-NEXT: retq
242+
%is_pos = icmp sgt i32 %a, 0
243+
%not_b = xor i1 %b, true
244+
%cond = and i1 %not_b, %is_pos
245+
%mask = insertelement <1 x i1> zeroinitializer, i1 %cond, i64 0
246+
call void @llvm.masked.store.v1i32.p0(<1 x i32> zeroinitializer, ptr null, i32 1, <1 x i1> %mask)
247+
ret void
248+
}
249+
233250
define i64 @redundant_test(i64 %num, ptr %p1, i64 %in) {
234251
; CHECK-LABEL: redundant_test:
235252
; CHECK: # %bb.0:

0 commit comments

Comments
 (0)