[llvm] BPF: Fix misfolding subregisters (PR #208244)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 07:31:10 PDT 2026


================
@@ -0,0 +1,43 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=bpfel -mattr=+alu32 -run-pass=bpf-mi-zext-elim %s -o - | FileCheck %s
+
+# Make sure that folds of MOV_32_64 respect a subregister index on the
+# source operand.
+
+---
+name:            mov32_64_subreg_source_imm
+tracksRegLiveness: true
+body:             |
+  bb.0:
+    liveins: $r1
+    ; CHECK-LABEL: name: mov32_64_subreg_source_imm
+    ; CHECK: liveins: $r1
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: [[LD_imm64_:%[0-9]+]]:gpr = LD_imm64 0
+    ; CHECK-NEXT: [[SUBREG_TO_REG:%[0-9]+]]:gpr = SUBREG_TO_REG [[LD_imm64_]], %subreg.sub_32
+    ; CHECK-NEXT: $r0 = COPY [[SUBREG_TO_REG]]
+    ; CHECK-NEXT: RET implicit $r0
----------------
yonghong-song wrote:

With this pull request, I tested with this .mir file and got the following:

```
body:             |                                                                                                          
  bb.0:                                                                                                                      
    liveins: $r1                                                                                                             
                                                                                                                             
    %0:gpr = LD_imm64 0                                                                                                      
    %1:gpr = SUBREG_TO_REG %0, %subreg.sub_32                                                                                
    $r0 = COPY %1                                                                                                            
    RET implicit $r0                                                                                                         
...
```

The `%1:gpr = SUBREG_TO_REG %0, %subreg.sub_32` is illegal. Here `%0` should be a subreg (`%0::gpr32`).

So you indeed find an issue, but your patch does not really fix the issue.

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


More information about the llvm-commits mailing list