Files
Nimit Sachdeva 2297e0d316 [MoveAutoInit] Fix for miscompilation for #150120 (#173961)
Fixes the miscompilation discussed for the PR #164882 as part of
generalizing the optimization for the issue #150120.

Without this commit, MoveAutoInit moves the store instruction to a
different branch which does not dominate the user dominator node. This
results in UB at runtime. The example in the test case is specifically
for an irreducible loop, in which all the predecessor may not dominate
user dominator head.

To fix this problem, we've introduced a new check to verify if the
predecessor of the user dominator node does in fact dominate user
dominator node before deciding that it is the node where the instruction
will be moved to.
2026-01-25 16:21:52 +01:00

60 lines
2.1 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
; RUN: opt -passes=move-auto-init -S < %s | FileCheck %s
define i8 @test_no_update(i32 %a, i32 %b) {
; CHECK-LABEL: define i8 @test_no_update
; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
; CHECK-NEXT: lbl_653:
; CHECK-NEXT: [[L_580:%.*]] = alloca i32, align 4
; CHECK-NEXT: store i32 1, ptr [[L_580]], align 4
; CHECK-NEXT: br i1 true, label [[LBL_629:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: br label [[IF_END:%.*]]
; CHECK: lbl_629:
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[L_580]], align 4
; CHECK-NEXT: [[TOBOOL223_NOT:%.*]] = icmp eq i32 [[TMP0]], 0
; CHECK-NEXT: br i1 [[TOBOOL223_NOT]], label [[LOR_RHS224:%.*]], label [[LOR_END230:%.*]]
; CHECK: lor.rhs224:
; CHECK-NEXT: [[TMP:%.*]] = alloca i8, align 1
; CHECK-NEXT: store i8 0, ptr [[TMP]], align 1
; CHECK-NEXT: br label [[LOR_END230]]
; CHECK: lor.end230:
; CHECK-NEXT: br i1 true, label [[FOR_INC456_1:%.*]], label [[LBL_629]]
; CHECK: for.inc456.1:
; CHECK-NEXT: ret i8 0
;
lbl_653:
%l_580 = alloca i32, align 4
store i32 1, ptr %l_580, align 4, !annotation !0
br i1 true, label %lbl_629, label %if.then
if.then: ; preds = %lbl_653
br label %if.end
lbl_629: ; preds = %lor.end230, %lbl_653
br label %if.end
if.end: ; preds = %lbl_629, %if.then
%0 = load i32, ptr %l_580, align 4
%tobool223.not = icmp eq i32 %0, 0
br i1 %tobool223.not, label %lor.rhs224, label %lor.end230
lor.rhs224: ; preds = %if.end
%tmp = alloca i8, align 1
store i8 0, ptr %tmp, align 1
br label %lor.end230
lor.end230: ; preds = %lor.rhs224, %if.end
br i1 true, label %for.inc456.1, label %lbl_629
for.inc456.1: ; preds = %lor.end230
ret i8 0
}
!0 = !{!"auto-init"}