Skip to content

clang is suboptimal for (~a ^ b) < ~a #69803

Closed
@k-arrows

Description

@k-arrows

Consider the following two functions:

int foo(int a, int b)
{
   return (~a ^ b) < ~a;
}

int bar(int a, int b)
{
   return (a ^ b) > a;
}

Clang vs GCC:
https://godbolt.org/z/rxK1nr794

Alive2:
https://alive2.llvm.org/ce/z/aUhKRe

define i32 @src(i32 %0, i32 %1) {
2:
  %3 = xor i32 %0, 4294967295
  %4 = xor i32 %3, %1
  %5 = icmp slt i32 %4, %3
  %6 = zext i1 %5 to i32
  ret i32 %6
}
=>
define i32 @tgt(i32 %0, i32 %1) {
2:
  %3 = xor i32 %1, %0
  %4 = icmp sgt i32 %3, %0
  %5 = zext i1 %4 to i32
  ret i32 %5
}
Transformation seems to be correct!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions