blob: 6a329db51d7c336306b153f023c9c37042321bde [file] [log] [blame]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -gvn -S %s | FileCheck %s
; Make sure GVN correctly sets the modified status when doing PRE.
define i32 @test(i64 %v, i32* %ptr.1, i32** %ptr.2, i1 %c) {
; CHECK-LABEL: @test(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[L_0:%.*]] = load i32, i32* [[PTR_1:%.*]], align 4
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK: if.then:
; CHECK-NEXT: ret i32 10
; CHECK: if.end:
; CHECK-NEXT: [[L_0_EXT:%.*]] = zext i32 [[L_0]] to i64
; CHECK-NEXT: [[C_2:%.*]] = icmp eq i64 [[L_0_EXT]], 10
; CHECK-NEXT: br i1 [[C_2]], label [[IF_2_END:%.*]], label [[IF_2_THEN:%.*]]
; CHECK: if.2.then:
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, i32* [[PTR_1]], i64 [[V:%.*]]
; CHECK-NEXT: [[L_2:%.*]] = load i32, i32* [[GEP_1]], align 4
; CHECK-NEXT: [[DOTPRE:%.*]] = zext i32 [[L_2]] to i64
; CHECK-NEXT: br label [[IF_2_END]]
; CHECK: if.2.end:
; CHECK-NEXT: [[REP_0_EXT_PRE_PHI:%.*]] = phi i64 [ [[DOTPRE]], [[IF_2_THEN]] ], [ 10, [[IF_END]] ]
; CHECK-NEXT: [[REP_0:%.*]] = phi i32 [ [[L_2]], [[IF_2_THEN]] ], [ [[L_0]], [[IF_END]] ]
; CHECK-NEXT: [[L_3:%.*]] = load i32*, i32** [[PTR_2:%.*]], align 8
; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i32, i32* [[PTR_1]], i64 [[REP_0_EXT_PRE_PHI]]
; CHECK-NEXT: [[L_4:%.*]] = load i32, i32* [[GEP_2]], align 4
; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr inbounds i32, i32* [[L_3]], i64 10
; CHECK-NEXT: [[L_5:%.*]] = load i32, i32* [[GEP_3]], align 4
; CHECK-NEXT: [[R:%.*]] = add i32 [[L_4]], [[L_5]]
; CHECK-NEXT: ret i32 [[R]]
;
entry:
%l.0 = load i32, i32* %ptr.1, align 4
br i1 %c, label %if.then, label %if.end
if.then: ; preds = %entry
ret i32 10
if.end: ; preds = %entry
%l.0.ext = zext i32 %l.0 to i64
%c.2 = icmp eq i64 %l.0.ext, 10
br i1 %c.2, label %if.2.end, label %if.2.then
if.2.then: ; preds = %if.end
%gep.1 = getelementptr inbounds i32, i32* %ptr.1, i64 %v
%l.2 = load i32, i32* %gep.1, align 4
br label %if.2.end
if.2.end: ; preds = %if.then7, %if.end
%rep.0 = phi i32 [ %l.2, %if.2.then ], [ %l.0, %if.end ]
%l.3 = load i32*, i32** %ptr.2, align 8
%rep.0.ext = zext i32 %rep.0 to i64
%gep.2 = getelementptr inbounds i32, i32* %ptr.1, i64 %rep.0.ext
%l.4 = load i32, i32* %gep.2, align 4
%gep.3 = getelementptr inbounds i32, i32* %l.3, i64 10
%l.5 = load i32, i32* %gep.3, align 4
%r = add i32 %l.4, %l.5
ret i32 %r
}