https://llvm.org/bugs/show_bug.cgi?id=31175
Bug ID: 31175 Summary: [AArch64] unnecessary cmp instruction with subtract and conditional select Product: libraries Version: trunk Hardware: PC OS: All Status: NEW Severity: normal Priority: P Component: Common Code Generator Code Assignee: unassignedb...@nondot.org Reporter: spatel+l...@rotateright.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified ; ret = (x-y) > 0 ? x-y : 0 define i32 @max(i32 %x, i32 %y) { %sub = sub nsw i32 %x, %y %cmp = icmp sgt i32 %sub, 0 %sel = select i1 %cmp, i32 %sub, i32 0 ret i32 %sel } Using AArch64 as the target because that shows the problem, but this is likely a bug for any target that has a subtract that sets comparison flags: $ ./llc -o - max.ll -mtriple=aarch64 sub w8, w0, w1 <--- could have used 'subs' cmp w8, #0 <--- and eliminated this cmp csel w0, w8, wzr, gt ret This IR equivalent shows the better codegen: define i32 @max_better(i32 %x, i32 %y) { %sub = sub nsw i32 %x, %y %cmp = icmp sgt i32 %x, %y %sel = select i1 %cmp, i32 %sub, i32 0 ret i32 %sel } $ ./llc -o - max.ll -mtriple=aarch64 subs w8, w0, w1 csel w0, w8, wzr, gt ret -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs