Commit c817509
Thorsten Schütt
[GlobalISel] Fix [SU]SUBO combine
The carry-out can participate in several positions:
* the condition of a select
* the condition of a conditional branch
* the carry-in of addes and subes (narrowScalarAddSub)
ADCS: Add with carry and set flags
Add with Carry, setting flags, adds two register values and the Carry
flag value, and writes the result to the destination register. It
updates the condition flags based on the result.
Note that the carry-in participates in the addition. It must be a 0 or
1 value. The carry-in/out values must be 0 or 1 for the addos, subos,
addes, and subos.
Including, but limited to the lowering for G_USUBO is buggy:
`MIRBuilder.buildICmp(CmpInst::ICMP_ULT, BorrowOut, LHS, RHS);`
The carry-out is target dependent and can lead to surprising and
non-deterministic results when used as carry-in.
narrowScalarAddSub can build chains of addes/subes. When the ops are
not negal for the current target and get lowered. They become chains
of adds/subs and icmps. The result will be come target dependent,
which is incorrect.
Lowering should write selects between one and zero constants into
carry-out registers.
AARrch64: ZeroOrOneBooleanContent
AMDGPU: ZeroOrNegativeOneBooleanContent
and ZeroOrOneBooleanContent
RISCV: ZeroOrOneBooleanContent1 parent 9bccf61 commit c817509
File tree
2 files changed
+25
-6
lines changed- llvm
- lib/CodeGen/GlobalISel
- test/CodeGen/AArch64/GlobalISel
2 files changed
+25
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7830 | 7830 | | |
7831 | 7831 | | |
7832 | 7832 | | |
7833 | | - | |
7834 | | - | |
7835 | | - | |
| 7833 | + | |
7836 | 7834 | | |
7837 | 7835 | | |
7838 | 7836 | | |
| |||
7855 | 7853 | | |
7856 | 7854 | | |
7857 | 7855 | | |
7858 | | - | |
7859 | | - | |
7860 | | - | |
| 7856 | + | |
7861 | 7857 | | |
7862 | 7858 | | |
7863 | 7859 | | |
| |||
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
0 commit comments