; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=newgvn -S | FileCheck %s
; RUN: opt < %s -passes=newgvn,jump-threading -S | FileCheck --check-prefix=CHECK-JT %s
; Test with std::pair<bool, int>
; based on the following C++ code
; std::pair<bool, int> callee(int v) {
; int a = dummy(v);
; if (a) return std::make_pair(true, dummy(a));
; else return std::make_pair(v < 0, v);
; }
; int func(int v) {
; std::pair<bool, int> rc = callee(v);
; if (rc.first) dummy(0);
; return rc.second;
; }
define signext i32 @testBI(i32 signext %v) {
; CHECK-LABEL: @testBI(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
; CHECK-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
; CHECK-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
; CHECK: if.then.i:
; CHECK-NEXT: [[CALL2_I:%.*]] = call signext i32 @dummy(i32 signext [[CALL_I]])
; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL2_I]] to i64
; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I_I]], 32
; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I]], 1
; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
; CHECK: if.else.i:
; CHECK-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I8_I:%.*]] = zext i32 [[V]] to i64
; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I8_I]], 32
; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I]], [[TMP0]]
; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT]]
; CHECK: _ZL6calleei.exit:
; CHECK-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I]], [[IF_ELSE_I]] ]
; CHECK-NEXT: [[RC_SROA_43_0_EXTRACT_SHIFT:%.*]] = lshr i64 [[RETVAL_SROA_0_0_I]], 32
; CHECK-NEXT: [[RC_SROA_43_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RC_SROA_43_0_EXTRACT_SHIFT]] to i32
; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 1
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: ret i32 [[RC_SROA_43_0_EXTRACT_TRUNC]]
;
; CHECK-JT-LABEL: @testBI(
; CHECK-JT-NEXT: entry:
; CHECK-JT-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
; CHECK-JT-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
; CHECK-JT-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
; CHECK-JT: if.then.i:
; CHECK-JT-NEXT: [[CALL2_I:%.*]] = call signext i32 @dummy(i32 signext [[CALL_I]])
; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL2_I]] to i64
; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I_I]], 32
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I]], 1
; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
; CHECK-JT: if.else.i:
; CHECK-JT-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
; CHECK-JT-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I8_I:%.*]] = zext i32 [[V]] to i64
; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I8_I]], 32
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I]], [[TMP0]]
; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT]]
; CHECK-JT: _ZL6calleei.exit:
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I]], [[IF_ELSE_I]] ]
; CHECK-JT-NEXT: [[RC_SROA_43_0_EXTRACT_SHIFT:%.*]] = lshr i64 [[RETVAL_SROA_0_0_I]], 32
; CHECK-JT-NEXT: [[RC_SROA_43_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RC_SROA_43_0_EXTRACT_SHIFT]] to i32
; CHECK-JT-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 1
; CHECK-JT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
; CHECK-JT-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
; CHECK-JT: if.then:
; CHECK-JT-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
; CHECK-JT-NEXT: br label [[IF_END]]
; CHECK-JT: if.end:
; CHECK-JT-NEXT: ret i32 [[RC_SROA_43_0_EXTRACT_TRUNC]]
;
entry:
%call.i = call signext i32 @dummy(i32 signext %v)
%tobool.i = icmp eq i32 %call.i, 0
br i1 %tobool.i, label %if.else.i, label %if.then.i
if.then.i: ; preds = %entry
%call2.i = call signext i32 @dummy(i32 signext %call.i)
%retval.sroa.22.0.insert.ext.i.i = zext i32 %call2.i to i64
%retval.sroa.22.0.insert.shift.i.i = shl nuw i64 %retval.sroa.22.0.insert.ext.i.i, 32
%retval.sroa.0.0.insert.insert.i.i = or i64 %retval.sroa.22.0.insert.shift.i.i, 1
br label %_ZL6calleei.exit
if.else.i: ; preds = %entry
%.lobit.i = lshr i32 %v, 31
%0 = zext i32 %.lobit.i to i64
%retval.sroa.22.0.insert.ext.i8.i = zext i32 %v to i64
%retval.sroa.22.0.insert.shift.i9.i = shl nuw i64 %retval.sroa.22.0.insert.ext.i8.i, 32
%retval.sroa.0.0.insert.insert.i11.i = or i64 %retval.sroa.22.0.insert.shift.i9.i, %0
br label %_ZL6calleei.exit
_ZL6calleei.exit: ; preds = %if.then.i, %if.else.i
%retval.sroa.0.0.i = phi i64 [ %retval.sroa.0.0.insert.insert.i.i, %if.then.i ], [ %retval.sroa.0.0.insert.insert.i11.i, %if.else.i ]
%rc.sroa.43.0.extract.shift = lshr i64 %retval.sroa.0.0.i, 32
%rc.sroa.43.0.extract.trunc = trunc i64 %rc.sroa.43.0.extract.shift to i32
%1 = and i64 %retval.sroa.0.0.i, 1
%tobool = icmp eq i64 %1, 0
br i1 %tobool, label %if.end, label %if.then
if.then: ; preds = %_ZL6calleei.exit
%call1 = call signext i32 @dummy(i32 signext 0)
br label %if.end
if.end: ; preds = %_ZL6calleei.exit, %if.then
ret i32 %rc.sroa.43.0.extract.trunc
}
; Test with std::pair<int, bool>
; based on the following C++ code
; std::pair<int, bool> callee(int v) {
; int a = dummy(v);
; if (a) return std::make_pair(dummy(v), true);
; else return std::make_pair(v, v < 0);
; }
; int func(int v) {
; std::pair<int, bool> rc = callee(v);
; if (rc.second) dummy(0);
; return rc.first;
; }
define signext i32 @testIB(i32 signext %v) {
; CHECK-LABEL: @testIB(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
; CHECK-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
; CHECK-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
; CHECK: if.then.i:
; CHECK-NEXT: [[CALL1_I:%.*]] = call signext i32 @dummy(i32 signext [[V]])
; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL1_I]] to i64
; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_0_0_INSERT_EXT_I_I]], 4294967296
; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
; CHECK: if.else.i:
; CHECK-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
; CHECK-NEXT: [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I:%.*]] = shl nuw nsw i64 [[TMP0]], 32
; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I9_I:%.*]] = zext i32 [[V]] to i64
; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I:%.*]] = or i64 [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I]], [[RETVAL_SROA_0_0_INSERT_EXT_I9_I]]
; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT]]
; CHECK: _ZL6calleei.exit:
; CHECK-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I]], [[IF_ELSE_I]] ]
; CHECK-NEXT: [[RC_SROA_0_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RETVAL_SROA_0_0_I]] to i32
; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 4294967296
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: ret i32 [[RC_SROA_0_0_EXTRACT_TRUNC]]
;
; CHECK-JT-LABEL: @testIB(
; CHECK-JT-NEXT: entry:
; CHECK-JT-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
; CHECK-JT-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
; CHECK-JT-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
; CHECK-JT: if.then.i:
; CHECK-JT-NEXT: [[CALL1_I:%.*]] = call signext i32 @dummy(i32 signext [[V]])
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL1_I]] to i64
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_0_0_INSERT_EXT_I_I]], 4294967296
; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
; CHECK-JT: if.else.i:
; CHECK-JT-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
; CHECK-JT-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
; CHECK-JT-NEXT: [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I:%.*]] = shl nuw nsw i64 [[TMP0]], 32
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I9_I:%.*]] = zext i32 [[V]] to i64
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I:%.*]] = or i64 [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I]], [[RETVAL_SROA_0_0_INSERT_EXT_I9_I]]
; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT]]
; CHECK-JT: _ZL6calleei.exit:
; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I]], [[IF_ELSE_I]] ]
; CHECK-JT-NEXT: [[RC_SROA_0_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RETVAL_SROA_0_0_I]] to i32
; CHECK-JT-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 4294967296
; CHECK-JT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
; CHECK-JT-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
; CHECK-JT: if.then:
; CHECK-JT-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
; CHECK-JT-NEXT: br label [[IF_END]]
; CHECK-JT: if.end:
; CHECK-JT-NEXT: ret i32 [[RC_SROA_0_0_EXTRACT_TRUNC]]
;
entry:
%call.i = call signext i32 @dummy(i32 signext %v)
%tobool.i = icmp eq i32 %call.i, 0
br i1 %tobool.i, label %if.else.i, label %if.then.i
if.then.i: ; preds = %entry
%call1.i = call signext i32 @dummy(i32 signext %v)
%retval.sroa.0.0.insert.ext.i.i = zext i32 %call1.i to i64
%retval.sroa.0.0.insert.insert.i.i = or i64 %retval.sroa.0.0.insert.ext.i.i, 4294967296
br label %_ZL6calleei.exit
if.else.i: ; preds = %entry
%.lobit.i = lshr i32 %v, 31
%0 = zext i32 %.lobit.i to i64
%retval.sroa.2.0.insert.shift.i8.i = shl nuw nsw i64 %0, 32
%retval.sroa.0.0.insert.ext.i9.i = zext i32 %v to i64
%retval.sroa.0.0.insert.insert.i10.i = or i64 %retval.sroa.2.0.insert.shift.i8.i, %retval.sroa.0.0.insert.ext.i9.i
br label %_ZL6calleei.exit
_ZL6calleei.exit: ; preds = %if.then.i, %if.else.i
%retval.sroa.0.0.i = phi i64 [ %retval.sroa.0.0.insert.insert.i.i, %if.then.i ], [ %retval.sroa.0.0.insert.insert.i10.i, %if.else.i ]
%rc.sroa.0.0.extract.trunc = trunc i64 %retval.sroa.0.0.i to i32
%1 = and i64 %retval.sroa.0.0.i, 4294967296
%tobool = icmp eq i64 %1, 0
br i1 %tobool, label %if.end, label %if.then
if.then: ; preds = %_ZL6calleei.exit
%call1 = call signext i32 @dummy(i32 signext 0)
br label %if.end
if.end: ; preds = %_ZL6calleei.exit, %if.then
ret i32 %rc.sroa.0.0.extract.trunc
}
declare signext i32 @dummy(i32 signext %v)