1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -O3 -S -enable-new-pm=0 < %s | FileCheck %s --check-prefixes=ALL
3 ; RUN: opt -passes='default<O3>' -S < %s | FileCheck %s --check-prefixes=ALL
5 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-unknown-linux-gnu"
8 ; PR51092: SimplifyCFG might produce duplicate PHI's/select's.
9 ; We need to deduplicate them so that further transformations are possible.
10 define dso_local void @foo(i32* %in, i64 %lo, i64 %hi, i32 %ishi) #0 {
13 ; ALL-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[ISHI:%.*]], 0
14 ; ALL-NEXT: [[LO_HI:%.*]] = select i1 [[TOBOOL_NOT]], i64 [[LO:%.*]], i64 [[HI:%.*]]
15 ; ALL-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, i32* [[IN:%.*]], i64 [[LO_HI]]
16 ; ALL-NEXT: [[ARRAYVAL2:%.*]] = load i32, i32* [[ARRAYIDX1]], align 4
17 ; ALL-NEXT: [[INC2:%.*]] = add nsw i32 [[ARRAYVAL2]], 1
18 ; ALL-NEXT: store i32 [[INC2]], i32* [[ARRAYIDX1]], align 4
22 %in.addr = alloca i32*, align 8
23 %lo.addr = alloca i64, align 8
24 %hi.addr = alloca i64, align 8
25 %ishi.addr = alloca i32, align 4
26 store i32* %in, i32** %in.addr, align 8
27 store i64 %lo, i64* %lo.addr, align 8
28 store i64 %hi, i64* %hi.addr, align 8
29 store i32 %ishi, i32* %ishi.addr, align 4
30 %ishi.reloaded = load i32, i32* %ishi.addr, align 4
31 %tobool = icmp ne i32 %ishi.reloaded, 0
32 br i1 %tobool, label %if.then, label %if.else
35 %in.reloaded = load i32*, i32** %in.addr, align 8
36 %hi.reloaded = load i64, i64* %hi.addr, align 8
37 %arrayidx = getelementptr inbounds i32, i32* %in.reloaded, i64 %hi.reloaded
38 %arrayval = load i32, i32* %arrayidx, align 4
39 %inc = add nsw i32 %arrayval, 1
40 store i32 %inc, i32* %arrayidx, align 4
44 %in.reloaded2 = load i32*, i32** %in.addr, align 8
45 %lo.reloaded = load i64, i64* %lo.addr, align 8
46 %arrayidx1 = getelementptr inbounds i32, i32* %in.reloaded2, i64 %lo.reloaded
47 %arrayval2 = load i32, i32* %arrayidx1, align 4
48 %inc2 = add nsw i32 %arrayval2, 1
49 store i32 %inc2, i32* %arrayidx1, align 4