[llvm] [X86] Don't always separate conditions in `(br (and/or cond0, cond1))` into separate branches (PR #81689)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 2 00:22:50 PST 2024


================
@@ -18,11 +18,13 @@ define void @test_dec_select(ptr nocapture %0, ptr readnone %1) {
 ; CHECK-LABEL: test_dec_select:
 ; CHECK:       # %bb.0:
 ; CHECK-NEXT:    lock decq (%rdi)
-; CHECK-NEXT:    jne .LBB0_2
-; CHECK-NEXT:  # %bb.1:
+; CHECK-NEXT:    sete %al
 ; CHECK-NEXT:    testq %rsi, %rsi
-; CHECK-NEXT:    jne func2 # TAILCALL
-; CHECK-NEXT:  .LBB0_2:
+; CHECK-NEXT:    setne %cl
+; CHECK-NEXT:    andb %al, %cl
+; CHECK-NEXT:    cmpb $1, %cl
----------------
goldsteinn wrote:

Seems to be because of the atomic.
```
SelectionDAG has 21 nodes:
  t0: ch,glue = EntryToken
    t2: i64,ch = CopyFromReg t0, Register:i64 %0
  t8: i8,ch = llvm.x86.atomic.sub.cc<(volatile load store (s64) on %ir.0, align 64)> t0, TargetConstant:i64<12197>, t2, Constant:i64<1>, TargetConstant:i32<4>
            t4: i64,ch = CopyFromReg t0, Register:i64 %1
          t12: i1 = setcc t4, Constant:i64<0>, setne:ch
          t9: i1 = truncate t8
        t14: i1 = select t12, t9, Constant:i1<0>
      t16: i1 = xor t14, Constant:i1<-1>
    t18: ch = brcond t8:1, t16, BasicBlock:ch< 0x55ddb51cd310>
  t20: ch = br t18, BasicBlock:ch< 0x55ddb51cd210>
```

We plumb `llvm.x86.atomic.sub.cc` as `i8` instead of `i1` and don't fold past the `truncate`.
Is there any reason `llvm.x86.atomic.sub.cc` needs to be `i8`?

https://github.com/llvm/llvm-project/pull/81689


More information about the llvm-commits mailing list