; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s

; Test for DAG combine: fold (not (sub Y, X)) -> (add X, ~Y)
; when Y is a constant.

; Test case 1: Y is a constant - should transform to (add X, ~Y)
define i32 @test_not_sub_constant(i32 %x) {
; CHECK-LABEL: test_not_sub_constant:
; CHECK:       # %bb.0:
; CHECK:         leal -101(%rdi), %eax
; CHECK-NEXT:    retq
  %sub = sub i32 100, %x
  %not = xor i32 %sub, -1
  ret i32 %not
}

; Test case 2: Y is not a constant - should NOT optimize
define i32 @test_not_sub_non_constant(i32 %x, i32 %y) {
; CHECK-LABEL: test_not_sub_non_constant:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movl %esi, %eax
; CHECK-NEXT:    subl %edi, %eax
; CHECK-NEXT:    notl %eax
; CHECK-NEXT:    retq
  %sub = sub i32 %y, %x
  %not = xor i32 %sub, -1
  ret i32 %not
}
