llvm-project/llvm/test/Transforms/CodeGenPrepare/X86/codegenprepare-hang-bitcast-phi.ll
nataliakokoromyti fa0071baab
[CodeGenPrepare] Fix infinite loop with same-type bitcasts (#176694)
OptimizeNoopCopyExpression was sinking same-type bitcasts (e.g. bitcast
i32 to i32) which would then be reintroduced by optimizePhiType, causing
an infinite loop.

Fix by adding a check (PhiTy == ConvertTy) in optimizePhiType to skip
the conversion when types are already identical.

Fixes #176688.
2026-01-22 09:29:08 +01:00

28 lines
910 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -S -mtriple=x86_64-unknown-linux-gnu -passes="require<profile-summary>,function(codegenprepare)" < %s | FileCheck %s
; Check that CodeGenPrepare does not hang on this input.
; This was caused by an infinite loop between OptimizeNoopCopyExpression
; and optimizePhiType when handling same-type bitcasts.
define void @foo(ptr %p) {
; CHECK-LABEL: define void @foo(
; CHECK-SAME: ptr [[P:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[P]], align 4
; CHECK-NEXT: store i32 [[VAL]], ptr [[P]], align 4
; CHECK-NEXT: ret void
;
entry:
%val = load i32, ptr %p, align 4
br i1 false, label %bb1, label %bb3
bb1:
%c1 = bitcast i32 %val to i32
br label %bb3
bb3:
%phi = phi i32 [ %c1, %bb1 ], [ %val, %entry ]
store i32 %phi, ptr %p, align 4
ret void
}