llvm-project/clang/test/CodeGen/inline-asm-x86-flag-output.c
Nikita Popov 05670b42f5 [InstCombine] Remove root special case in demanded bits simplification
When calling SimplifyDemandedBits (as opposed to
SimplifyDemandedInstructionBits), and there are multiple uses,
always use SimplifyMultipleUseDemandedBits and drop the special
case for root values.

This fixes the ephemeral value detection, as seen by the restored
assumes in tests. It may result in more or less simplification,
depending on whether we get more out of having demanded bits or
the ability to perform non-multi-use transforms. The change in
the phi-known-bits.ll test is because the icmp operand now gets
simplified based on demanded bits, which then prevents a different
known bits simplification later.

This also makes the code safe against future changes like
https://github.com/llvm/llvm-project/pull/97289, which add more
context that would have to be discarded for the multi-use case.
2024-07-02 11:14:36 +02:00

396 lines
11 KiB
C

// RUN: %clang_cc1 -O2 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
int test_cca(long nr, volatile long *addr) {
//CHECK-LABEL: @test_cca
//CHECK: = tail call i32 asm "cmp $2,$1", "={@cca},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@cca"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccae(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccae
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccae"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccb(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccb
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccb},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccb"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccbe(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccbe
//CHECK: tail call i32 asm "cmp $2,$1", "={@ccbe},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccbe"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccc(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccc
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccc},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccc"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_cce(long nr, volatile long *addr) {
//CHECK-LABEL: @test_cce
//CHECK: = tail call i32 asm "cmp $2,$1", "={@cce},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@cce"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccz(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccz
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccz},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccz"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccg(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccg
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccg},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccg"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccge(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccge
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccge},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccge"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccl(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccl
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccl},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccl"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccle(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccle
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccle},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccle"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccna(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccna
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccna},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccna"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnae(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnae
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnae"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnb(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnb
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnb},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnb"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnbe(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnbe
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnbe},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnbe"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnc(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnc
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnc},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnc"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccne(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccne
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccne},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccne"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnz(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnz
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnz},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnz"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccng(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccng
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccng},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccng"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnge(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnge
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnge},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnge"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnl(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnl
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnl},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnl"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnle(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnle
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnle},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnle"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccno(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccno
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccno},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccno"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccnp(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccnp
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccnp},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccnp"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccns(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccns
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccns},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccns"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_cco(long nr, volatile long *addr) {
//CHECK-LABEL: @test_cco
//CHECK: = tail call i32 asm "cmp $2,$1", "={@cco},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@cco"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccp(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccp
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccp},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccp"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
int test_ccs(long nr, volatile long *addr) {
//CHECK-LABEL: @test_ccs
//CHECK: = tail call i32 asm "cmp $2,$1", "={@ccs},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
int x;
asm("cmp %2,%1"
: "=@ccs"(x), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}
_Bool check_no_clobber_conflicts(void) {
//CHECK-LABEL: @check_no_clobber_conflicts
//CHECK: = tail call i8 asm "", "={@cce},~{cx},~{dirflag},~{fpsr},~{flags}"()
_Bool b;
asm(""
: "=@cce"(b)
:
: "cx");
return b;
}
int test_assume_boolean_flag(long nr, volatile long *addr) {
//CHECK-LABEL: @test_assume_boolean_flag
//CHECK: %0 = tail call { i32, i32 } asm "cmp $2,$1", "={@cca},={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr)
//CHECK: [[RES1:%.*]] = extractvalue { i32, i32 } %0, 0
//CHECK: [[RES2:%.*]] = extractvalue { i32, i32 } %0, 1
//CHECK: %1 = icmp ult i32 [[RES1]], 2
//CHECK: tail call void @llvm.assume(i1 %1)
//CHECK: %2 = icmp ult i32 [[RES2]], 2
//CHECK: tail call void @llvm.assume(i1 %2)
int x,y;
asm("cmp %2,%1"
: "=@cca"(x), "=@ccae"(y), "=m"(*(volatile long *)(addr))
: "r"(nr)
: "cc");
if (x)
return 0;
return 1;
}