[llvm] [TwoAddressInstruction] Propagate undef flags for partial defs (PR #79286)

Carl Ritson via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 19:01:15 PST 2024


perlfu wrote:

I've switch this to a concrete MIR example.

The root cause could be seen as an issue/bug with GlobalISel code gen, although I think this change is still beneficial.
In this case there is an extractelement on a v7 type, which must be widened to v8 for code gen:
`%ext = extractelement <7 x double> %vec, i32 %sel`

The result is that GlobalISel generates a `REG_SEQUENCE` with an undef (see last element):
```
%34:vreg_512 = REG_SEQUENCE %16, %subreg.sub0_sub1, %17, %subreg.sub2_sub3, %18, %subreg.sub4_sub5, %19, %subreg.sub6_sub7, %20, %subreg.sub8_sub9, %21, %subreg.sub10_sub11, %22, %subreg.sub12_sub13, undef %35:vreg_64, %subreg.sub14_sub15
```

Then generates code to extract that element if selected:
```   
%80:vgpr_32 = V_CNDMASK_B32_e64 0, %76, 0, %34.sub14, %79, implicit $exec
%81:vgpr_32 = V_CNDMASK_B32_e64 0, %77, 0, %34.sub15, %79, implicit $exec
```

Without propagating the undef flags, the above instructions will fail the verifier if LiveIntervals are available.

https://github.com/llvm/llvm-project/pull/79286


More information about the llvm-commits mailing list