| Issue |
239126
|
| Summary |
[IROutliner] Output stores left in unreachable blocks when two regions store the same outputs differently
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
fazxes
|
When two regions in a group store the same set of outputs from different values, the outlined function gets one output block per store scheme but no switch that picks between them. The output blocks have no predecessors, so the stores never run and each caller reads its output slot uninitialized. Release builds do not hit the assertion that would catch it.
Reproduces with LLVM 22.1.8 (reduced from a real program with `llvm-reduce`):
```
opt -S -passes=iroutliner reproB.ll
```
<details><summary>reproB.ll</summary>
```llvm
; LLVM 22.1.8 IR outliner: an output store left in blocks with no predecessors.
; Reduced by llvm-reduce from six fx footer functions (fx-3517cdf/current/swapped.bc).
; Run: opt -S -passes=iroutliner reproB-orphaned-output.ll
; outlined_ir_func_0 gets two PHIs for the same output and two output blocks,
; output_block_0_0 and output_block_1_0, that nothing branches to, so neither
; call site's %.sroa.957.0.ce.loc is ever written.
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-apple-macosx15.0.0-unknown"
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #0
define fastcc i16 @ui.footer.picker_presentation.composeAuthPickerRow() {
br label %.preheader155
.preheader155: ; preds = %0
br i1 false, label %ui.footer.picker_presentation.composeSignInPickerRow.exit, label %.critedge.i9
.critedge.i9: ; preds = %.preheader155
br i1 false, label %ui.footer.picker_presentation.composeSignInPickerRow.exit, label %ui.footer.picker_presentation.composeSignInPickerRow.exit
1: ; No predecessors!
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit
2: ; No predecessors!
br i1 false, label %ui.footer.picker_presentation.composeSignInPickerRow.exit, label %ui.footer.picker_presentation.composeSignInPickerRow.exit
.critedge194.i: ; No predecessors!
br i1 false, label %ui.footer.picker_presentation.composeSignInPickerRow.exit, label %.critedge197.i
.loopexit: ; No predecessors!
%3 = call fastcc i16 @"array_list.Aligned(u8,null).appendSlice"(ptr null, i64 0)
%.not161.i = icmp eq i16 0, 0
br i1 false, label %5, label %4
4: ; preds = %.loopexit
store i32 0, ptr null, align 4
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit
5: ; preds = %.loopexit
call void @llvm.memcpy.p0.p0.i64(ptr null, ptr null, i64 0, i1 false)
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit
.critedge197.i: ; preds = %.critedge194.i
%6 = call fastcc i16 @"array_list.Aligned(u8,null).appendSlice"(ptr null, i64 0)
%.not154.i = icmp eq i16 0, 0
br i1 false, label %8, label %7
7: ; preds = %.critedge197.i
store i32 0, ptr null, align 4
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit
8: ; preds = %.critedge197.i
call void @llvm.memcpy.p0.p0.i64(ptr null, ptr null, i64 0, i1 false)
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit
ui.footer.picker_presentation.composeSignInPickerRow.exit: ; preds = %8, %7, %5, %4, %.critedge194.i, %2, %2, %1, %.critedge.i9, %.critedge.i9, %.preheader155
%.sroa.957.0 = phi i16 [ 0, %2 ], [ 0, %2 ], [ 0, %.critedge.i9 ], [ 0, %.critedge.i9 ], [ 0, %1 ], [ 0, %5 ], [ 0, %4 ], [ 0, %.preheader155 ], [ 0, %8 ], [ 0, %7 ], [ 0, %.critedge194.i ]
ret i16 0
}
declare fastcc i16 @"array_list.Aligned(u8,null).appendSlice"(ptr, i64)
attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
```
</details>
Both output blocks of the outlined function are unreachable:
```llvm
define internal void @outlined_ir_func_0(ptr %0) #2 {
newFuncRoot:
br label %.loopexit_to_outline
.loopexit_to_outline: ; preds = %newFuncRoot
%1 = call fastcc i16 @"array_list.Aligned(u8,null).appendSlice"(ptr null, i64 0)
%.not161.i = icmp eq i16 0, 0
br i1 false, label %3, label %2
2: ; preds = %.loopexit_to_outline
store i32 0, ptr null, align 4
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit.split
3: ; preds = %.loopexit_to_outline
call void @llvm.memcpy.p0.p0.i64(ptr null, ptr null, i64 0, i1 false)
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit.split
ui.footer.picker_presentation.composeSignInPickerRow.exit.split: ; preds = %2, %3
%4 = phi i16 [ 0, %2 ], [ 0, %3 ]
%.sroa.957.0.ce = phi i16 [ 0, %3 ], [ 0, %2 ]
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit.exitStub
ui.footer.picker_presentation.composeSignInPickerRow.exit.exitStub: ; preds = %output_block_1_0, %output_block_0_0, %ui.footer.picker_presentation.composeSignInPickerRow.exit.split
ret void
output_block_0_0: ; No predecessors!
store i16 %.sroa.957.0.ce, ptr %0, align 2
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit.exitStub
output_block_1_0: ; No predecessors!
store i16 %4, ptr %0, align 2
br label %ui.footer.picker_presentation.composeSignInPickerRow.exit.exitStub
}
```
As far as I can tell, `createSwitchStatement` (IROutliner.cpp, line 2126 at llvmorg-22.1.8) builds the switch only when there is more than one store combination. Here both regions produce the same set of output GVNs, so it takes the single-set path, and `assert(OutputStoreBBs.size() < 2 && "Different store sets not handled!")` at line 2178 is the only guard. An assertions build stops there instead.
We work around it by finding outlined functions with a non-entry block that nothing branches to, marking their callers `nooutline`, and outlining again.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs