LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 47873 - Regressions for conditional code gen from clang 10 to 11
Summary: Regressions for conditional code gen from clang 10 to 11
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: 11.0
Hardware: PC Windows NT
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-15 22:41 PDT by Fabian Giesen
Modified: 2021-01-13 01:28 PST (History)
7 users (show)

See Also:
Fixed By Commit(s): 25eb7b08ba77


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabian Giesen 2020-10-15 22:41:03 PDT
Small repro here: https://godbolt.org/z/xPPGMv

11.0 and trunk both produce the "cmp edx, ecx" / "seta cl" / "test cl, 1" / "jne label" construction that serves no purpose I can discern; 10.0.1 and earlier used the expected "cmp edx, ecx" / "ja label".

This function makes for a particularly simple reproducer but we're seeing instances of this in many places in our code base.
Comment 1 Craig Topper 2020-10-15 23:32:24 PDT
I think this has something to do with a freeze instruction being inserted in CodeGenPrepare.
Comment 2 Juneyoung Lee 2020-10-16 22:57:54 PDT
Yes, it is due to CodeGenPrepare's select cond -> br freeze(cond):

```
  %cmp = icmp ugt i32 %math, %1
  %cond = select i1 %ov, i32 %0, i32 %1
  %x.addr.0.frozen = freeze i1 %cmp
  br i1 %x.addr.0.frozen, label %select.end, label %select.false, !prof !7

select.false:                                     ; preds = %entry
  br label %select.end

select.end:                                       ; preds = %entry, %select.false
  %x.addr.0 = phi i32 [ %cond, %entry ], [ %x, %select.false ]
  ret i32 %x.addr.0
```

After X86 DAG->DAG Instruction Selection, it becomes:

```
bb.0.entry:
  ...
  %12:gr8 = SETCCr 7, implicit $eflags           
  %13:gr8 = COPY killed %12:gr8                  
  TEST8ri killed %13:gr8, 1, implicit-def $eflags
  JCC_1 %bb.2, 5, implicit $eflags               
  JMP_1 %bb.1
```

Without freeze:
```
  ...
  JCC_1 %bb.2, 7, implicit $eflags
  JMP_1 %bb.1
```

I'm seeing whether it can be addressed at instruction selection level.
Comment 3 David Bolvansky 2020-12-08 20:06:12 PST
Any progress?
Comment 4 Juneyoung Lee 2020-12-08 23:23:24 PST
The patch link is here: https://reviews.llvm.org/D92015
Comment 5 Juneyoung Lee 2021-01-12 17:02:46 PST
Should be fixed now