1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals 2; RUN: opt -enable-new-pm=0 -attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=20 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM 3; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=20 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM 4; RUN: opt -enable-new-pm=0 -attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM 5; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM 6; 7; Test for multiple potential values 8; 9; potential-test 1 10; bool iszero(int c) { return c == 0; } 11; bool potential_test1(bool c) { return iszero(c ? 1 : -1); } 12 13define internal i1 @iszero1(i32 %c) { 14; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 15; IS__CGSCC____-LABEL: define {{[^@]+}}@iszero1 16; IS__CGSCC____-SAME: (i32 noundef [[C:%.*]]) #[[ATTR0:[0-9]+]] { 17; IS__CGSCC____-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 0 18; IS__CGSCC____-NEXT: ret i1 [[CMP]] 19; 20 %cmp = icmp eq i32 %c, 0 21 ret i1 %cmp 22} 23 24define i1 @potential_test1(i1 %c) { 25; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 26; IS__TUNIT____-LABEL: define {{[^@]+}}@potential_test1 27; IS__TUNIT____-SAME: (i1 [[C:%.*]]) #[[ATTR0:[0-9]+]] { 28; IS__TUNIT____-NEXT: ret i1 false 29; 30; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 31; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test1 32; IS__CGSCC_OPM-SAME: (i1 [[C:%.*]]) #[[ATTR1:[0-9]+]] { 33; IS__CGSCC_OPM-NEXT: [[ARG:%.*]] = select i1 [[C]], i32 -1, i32 1 34; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = call i1 @iszero1(i32 noundef [[ARG]]) #[[ATTR3:[0-9]+]] 35; IS__CGSCC_OPM-NEXT: ret i1 [[RET]] 36; 37; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 38; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test1 39; IS__CGSCC_NPM-SAME: (i1 [[C:%.*]]) #[[ATTR1:[0-9]+]] { 40; IS__CGSCC_NPM-NEXT: [[ARG:%.*]] = select i1 [[C]], i32 -1, i32 1 41; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = call i1 @iszero1(i32 noundef [[ARG]]) #[[ATTR2:[0-9]+]] 42; IS__CGSCC_NPM-NEXT: ret i1 [[RET]] 43; 44 %arg = select i1 %c, i32 -1, i32 1 45 %ret = call i1 @iszero1(i32 %arg) 46 ret i1 %ret 47} 48 49 50; potential-test 2 51; 52; potential values of argument of iszero are {1,-1} 53; potential value of returned value of iszero is 0 54; 55; int call_with_two_values(int x) { return iszero(x) + iszero(-x); } 56; int potential_test2(int x) { return call_with_two_values(1) + call_with_two_values(-1); } 57 58define internal i32 @iszero2(i32 %c) { 59; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 60; IS__CGSCC____-LABEL: define {{[^@]+}}@iszero2 61; IS__CGSCC____-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 62; IS__CGSCC____-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 0 63; IS__CGSCC____-NEXT: [[RET:%.*]] = zext i1 [[CMP]] to i32 64; IS__CGSCC____-NEXT: ret i32 [[RET]] 65; 66 %cmp = icmp eq i32 %c, 0 67 %ret = zext i1 %cmp to i32 68 ret i32 %ret 69} 70 71define internal i32 @call_with_two_values(i32 %c) { 72; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 73; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@call_with_two_values 74; IS__CGSCC_OPM-SAME: (i32 noundef [[C:%.*]]) #[[ATTR1]] { 75; IS__CGSCC_OPM-NEXT: [[CSRET1:%.*]] = call i32 @iszero2(i32 noundef [[C]]) #[[ATTR3]] 76; IS__CGSCC_OPM-NEXT: [[MINUSC:%.*]] = sub i32 0, [[C]] 77; IS__CGSCC_OPM-NEXT: [[CSRET2:%.*]] = call i32 @iszero2(i32 [[MINUSC]]) #[[ATTR3]] 78; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = add i32 [[CSRET1]], [[CSRET2]] 79; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 80; 81; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 82; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@call_with_two_values 83; IS__CGSCC_NPM-SAME: (i32 noundef [[C:%.*]]) #[[ATTR1]] { 84; IS__CGSCC_NPM-NEXT: [[CSRET1:%.*]] = call i32 @iszero2(i32 noundef [[C]]) #[[ATTR2]] 85; IS__CGSCC_NPM-NEXT: [[MINUSC:%.*]] = sub i32 0, [[C]] 86; IS__CGSCC_NPM-NEXT: [[CSRET2:%.*]] = call i32 @iszero2(i32 [[MINUSC]]) #[[ATTR2]] 87; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = add i32 [[CSRET1]], [[CSRET2]] 88; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 89; 90 %csret1 = call i32 @iszero2(i32 %c) 91 %minusc = sub i32 0, %c 92 %csret2 = call i32 @iszero2(i32 %minusc) 93 %ret = add i32 %csret1, %csret2 94 ret i32 %ret 95} 96 97define i32 @potential_test2(i1 %c) { 98; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 99; IS__TUNIT____-LABEL: define {{[^@]+}}@potential_test2 100; IS__TUNIT____-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 101; IS__TUNIT____-NEXT: ret i32 0 102; 103; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 104; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test2 105; IS__CGSCC_OPM-SAME: (i1 [[C:%.*]]) #[[ATTR1]] { 106; IS__CGSCC_OPM-NEXT: [[CSRET1:%.*]] = call i32 @call_with_two_values(i32 noundef 1) #[[ATTR3]] 107; IS__CGSCC_OPM-NEXT: [[CSRET2:%.*]] = call i32 @call_with_two_values(i32 noundef -1) #[[ATTR3]] 108; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = add i32 [[CSRET1]], [[CSRET2]] 109; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 110; 111; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 112; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test2 113; IS__CGSCC_NPM-SAME: (i1 [[C:%.*]]) #[[ATTR1]] { 114; IS__CGSCC_NPM-NEXT: [[CSRET1:%.*]] = call i32 @call_with_two_values(i32 noundef 1) #[[ATTR2]] 115; IS__CGSCC_NPM-NEXT: [[CSRET2:%.*]] = call i32 @call_with_two_values(i32 noundef -1) #[[ATTR2]] 116; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = add i32 [[CSRET1]], [[CSRET2]] 117; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 118; 119 %csret1 = call i32 @call_with_two_values(i32 1) 120 %csret2 = call i32 @call_with_two_values(i32 -1) 121 %ret = add i32 %csret1, %csret2 122 ret i32 %ret 123} 124 125 126; potential-test 3 127; 128; potential values of returned value of f are {0,1} 129; potential values of argument of g are {0,1} 130; potential value of returned value of g is 1 131; then returned value of g can be simplified 132; 133; int zero_or_one(int c) { return c < 2; } 134; int potential_test3() { return zero_or_one(iszero(0))+zero_or_one(iszero(1)); } 135 136define internal i32 @iszero3(i32 %c) { 137; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 138; IS__CGSCC____-LABEL: define {{[^@]+}}@iszero3 139; IS__CGSCC____-SAME: (i32 noundef [[C:%.*]]) #[[ATTR0]] { 140; IS__CGSCC____-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 0 141; IS__CGSCC____-NEXT: [[RET:%.*]] = zext i1 [[CMP]] to i32 142; IS__CGSCC____-NEXT: ret i32 [[RET]] 143; 144 %cmp = icmp eq i32 %c, 0 145 %ret = zext i1 %cmp to i32 146 ret i32 %ret 147} 148 149define internal i32 @less_than_two(i32 %c) { 150; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 151; IS__CGSCC____-LABEL: define {{[^@]+}}@less_than_two 152; IS__CGSCC____-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 153; IS__CGSCC____-NEXT: [[CMP:%.*]] = icmp slt i32 [[C]], 2 154; IS__CGSCC____-NEXT: [[RET:%.*]] = zext i1 [[CMP]] to i32 155; IS__CGSCC____-NEXT: ret i32 [[RET]] 156; 157 %cmp = icmp slt i32 %c, 2 158 %ret = zext i1 %cmp to i32 159 ret i32 %ret 160} 161 162define i32 @potential_test3() { 163; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 164; IS__TUNIT____-LABEL: define {{[^@]+}}@potential_test3 165; IS__TUNIT____-SAME: () #[[ATTR0]] { 166; IS__TUNIT____-NEXT: ret i32 2 167; 168; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 169; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test3 170; IS__CGSCC_OPM-SAME: () #[[ATTR1]] { 171; IS__CGSCC_OPM-NEXT: [[CMP1:%.*]] = call i32 @iszero3(i32 noundef 0) #[[ATTR3]] 172; IS__CGSCC_OPM-NEXT: [[TRUE1:%.*]] = call i32 @less_than_two(i32 [[CMP1]]) #[[ATTR3]] 173; IS__CGSCC_OPM-NEXT: [[CMP2:%.*]] = call i32 @iszero3(i32 noundef 1) #[[ATTR3]] 174; IS__CGSCC_OPM-NEXT: [[TRUE2:%.*]] = call i32 @less_than_two(i32 [[CMP2]]) #[[ATTR3]] 175; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = add i32 [[TRUE1]], [[TRUE2]] 176; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 177; 178; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 179; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test3 180; IS__CGSCC_NPM-SAME: () #[[ATTR1]] { 181; IS__CGSCC_NPM-NEXT: [[CMP1:%.*]] = call i32 @iszero3(i32 noundef 0) #[[ATTR2]] 182; IS__CGSCC_NPM-NEXT: [[TRUE1:%.*]] = call i32 @less_than_two(i32 [[CMP1]]) #[[ATTR2]] 183; IS__CGSCC_NPM-NEXT: [[CMP2:%.*]] = call i32 @iszero3(i32 noundef 1) #[[ATTR2]] 184; IS__CGSCC_NPM-NEXT: [[TRUE2:%.*]] = call i32 @less_than_two(i32 [[CMP2]]) #[[ATTR2]] 185; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = add i32 [[TRUE1]], [[TRUE2]] 186; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 187; 188 %cmp1 = call i32 @iszero3(i32 0) 189 %true1 = call i32 @less_than_two(i32 %cmp1) 190 %cmp2 = call i32 @iszero3(i32 1) 191 %true2 = call i32 @less_than_two(i32 %cmp2) 192 %ret = add i32 %true1, %true2 193 ret i32 %ret 194} 195 196 197; potential-test 4,5 198; 199; simplified 200; int potential_test4(int c) { return return1or3(c) == 2; } 201; int potential_test5(int c) { return return1or3(c) == return2or4(c); } 202; 203; not simplified 204; int potential_test6(int c) { return return1or3(c) == 3; } 205; int potential_test7(int c) { return return1or3(c) == return3or4(c); } 206 207define i32 @potential_test4(i32 %c) { 208; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 209; IS__TUNIT____-LABEL: define {{[^@]+}}@potential_test4 210; IS__TUNIT____-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 211; IS__TUNIT____-NEXT: ret i32 0 212; 213; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 214; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test4 215; IS__CGSCC_OPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 216; IS__CGSCC_OPM-NEXT: [[CSRET:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR3]] 217; IS__CGSCC_OPM-NEXT: [[FALSE:%.*]] = icmp eq i32 [[CSRET]], 2 218; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = zext i1 [[FALSE]] to i32 219; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 220; 221; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 222; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test4 223; IS__CGSCC_NPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 224; IS__CGSCC_NPM-NEXT: [[CSRET:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR2]] 225; IS__CGSCC_NPM-NEXT: [[FALSE:%.*]] = icmp eq i32 [[CSRET]], 2 226; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = zext i1 [[FALSE]] to i32 227; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 228; 229 %csret = call i32 @return1or3(i32 %c) 230 %false = icmp eq i32 %csret, 2 231 %ret = zext i1 %false to i32 232 ret i32 %ret 233} 234 235define i32 @potential_test5(i32 %c) { 236; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 237; IS__TUNIT____-LABEL: define {{[^@]+}}@potential_test5 238; IS__TUNIT____-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 239; IS__TUNIT____-NEXT: ret i32 0 240; 241; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 242; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test5 243; IS__CGSCC_OPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 244; IS__CGSCC_OPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR3]] 245; IS__CGSCC_OPM-NEXT: [[CSRET2:%.*]] = call i32 @return2or4(i32 [[C]]) #[[ATTR3]] 246; IS__CGSCC_OPM-NEXT: [[FALSE:%.*]] = icmp eq i32 [[CSRET1]], [[CSRET2]] 247; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = zext i1 [[FALSE]] to i32 248; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 249; 250; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 251; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test5 252; IS__CGSCC_NPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 253; IS__CGSCC_NPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR2]] 254; IS__CGSCC_NPM-NEXT: [[CSRET2:%.*]] = call i32 @return2or4(i32 [[C]]) #[[ATTR2]] 255; IS__CGSCC_NPM-NEXT: [[FALSE:%.*]] = icmp eq i32 [[CSRET1]], [[CSRET2]] 256; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = zext i1 [[FALSE]] to i32 257; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 258; 259 %csret1 = call i32 @return1or3(i32 %c) 260 %csret2 = call i32 @return2or4(i32 %c) 261 %false = icmp eq i32 %csret1, %csret2 262 %ret = zext i1 %false to i32 263 ret i32 %ret 264} 265 266define i1 @potential_test6(i32 %c) { 267; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 268; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test6 269; IS__TUNIT_OPM-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 270; IS__TUNIT_OPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR2:[0-9]+]], !range [[RNG0:![0-9]+]] 271; IS__TUNIT_OPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], 3 272; IS__TUNIT_OPM-NEXT: ret i1 [[RET]] 273; 274; IS__TUNIT_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 275; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@potential_test6 276; IS__TUNIT_NPM-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 277; IS__TUNIT_NPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR1:[0-9]+]], !range [[RNG0:![0-9]+]] 278; IS__TUNIT_NPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], 3 279; IS__TUNIT_NPM-NEXT: ret i1 [[RET]] 280; 281; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 282; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test6 283; IS__CGSCC_OPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 284; IS__CGSCC_OPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR3]] 285; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], 3 286; IS__CGSCC_OPM-NEXT: ret i1 [[RET]] 287; 288; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 289; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test6 290; IS__CGSCC_NPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 291; IS__CGSCC_NPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR2]] 292; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], 3 293; IS__CGSCC_NPM-NEXT: ret i1 [[RET]] 294; 295 %csret1 = call i32 @return1or3(i32 %c) 296 %ret = icmp eq i32 %csret1, 3 297 ret i1 %ret 298} 299 300define i1 @potential_test7(i32 %c) { 301; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 302; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test7 303; IS__TUNIT_OPM-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 304; IS__TUNIT_OPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR2]], !range [[RNG0]] 305; IS__TUNIT_OPM-NEXT: [[CSRET2:%.*]] = call i32 @return3or4(i32 [[C]]) #[[ATTR2]], !range [[RNG1:![0-9]+]] 306; IS__TUNIT_OPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], [[CSRET2]] 307; IS__TUNIT_OPM-NEXT: ret i1 [[RET]] 308; 309; IS__TUNIT_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 310; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@potential_test7 311; IS__TUNIT_NPM-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 312; IS__TUNIT_NPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR1]], !range [[RNG0]] 313; IS__TUNIT_NPM-NEXT: [[CSRET2:%.*]] = call i32 @return3or4(i32 [[C]]) #[[ATTR1]], !range [[RNG1:![0-9]+]] 314; IS__TUNIT_NPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], [[CSRET2]] 315; IS__TUNIT_NPM-NEXT: ret i1 [[RET]] 316; 317; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 318; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test7 319; IS__CGSCC_OPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 320; IS__CGSCC_OPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR3]] 321; IS__CGSCC_OPM-NEXT: [[CSRET2:%.*]] = call i32 @return3or4(i32 [[C]]) #[[ATTR3]] 322; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], [[CSRET2]] 323; IS__CGSCC_OPM-NEXT: ret i1 [[RET]] 324; 325; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 326; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test7 327; IS__CGSCC_NPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 328; IS__CGSCC_NPM-NEXT: [[CSRET1:%.*]] = call i32 @return1or3(i32 [[C]]) #[[ATTR2]] 329; IS__CGSCC_NPM-NEXT: [[CSRET2:%.*]] = call i32 @return3or4(i32 [[C]]) #[[ATTR2]] 330; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = icmp eq i32 [[CSRET1]], [[CSRET2]] 331; IS__CGSCC_NPM-NEXT: ret i1 [[RET]] 332; 333 %csret1 = call i32 @return1or3(i32 %c) 334 %csret2 = call i32 @return3or4(i32 %c) 335 %ret = icmp eq i32 %csret1, %csret2 336 ret i1 %ret 337} 338 339define internal i32 @return1or3(i32 %c) { 340; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 341; CHECK-LABEL: define {{[^@]+}}@return1or3 342; CHECK-SAME: (i32 [[C:%.*]]) #[[ATTR0:[0-9]+]] { 343; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 0 344; CHECK-NEXT: [[RET:%.*]] = select i1 [[CMP]], i32 1, i32 3 345; CHECK-NEXT: ret i32 [[RET]] 346; 347 %cmp = icmp eq i32 %c, 0 348 %ret = select i1 %cmp, i32 1, i32 3 349 ret i32 %ret 350} 351 352define internal i32 @return2or4(i32 %c) { 353; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 354; IS__CGSCC____-LABEL: define {{[^@]+}}@return2or4 355; IS__CGSCC____-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 356; IS__CGSCC____-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 0 357; IS__CGSCC____-NEXT: [[RET:%.*]] = select i1 [[CMP]], i32 2, i32 4 358; IS__CGSCC____-NEXT: ret i32 [[RET]] 359; 360 %cmp = icmp eq i32 %c, 0 361 %ret = select i1 %cmp, i32 2, i32 4 362 ret i32 %ret 363} 364 365define internal i32 @return3or4(i32 %c) { 366; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 367; CHECK-LABEL: define {{[^@]+}}@return3or4 368; CHECK-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 369; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 0 370; CHECK-NEXT: [[RET:%.*]] = select i1 [[CMP]], i32 3, i32 4 371; CHECK-NEXT: ret i32 [[RET]] 372; 373 %cmp = icmp eq i32 %c, 0 374 %ret = select i1 %cmp, i32 3, i32 4 375 ret i32 %ret 376} 377 378; potential-test 8 379; 380; propagate argument to callsite argument 381 382define internal i1 @cmp_with_four(i32 %c) { 383; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 384; IS__CGSCC____-LABEL: define {{[^@]+}}@cmp_with_four 385; IS__CGSCC____-SAME: (i32 noundef [[C:%.*]]) #[[ATTR0]] { 386; IS__CGSCC____-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 4 387; IS__CGSCC____-NEXT: ret i1 [[CMP]] 388; 389 %cmp = icmp eq i32 %c, 4 390 ret i1 %cmp 391} 392 393define internal i1 @wrapper(i32 %c) { 394; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 395; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@wrapper 396; IS__CGSCC_OPM-SAME: (i32 noundef [[C:%.*]]) #[[ATTR1]] { 397; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = call i1 @cmp_with_four(i32 noundef [[C]]) #[[ATTR3]] 398; IS__CGSCC_OPM-NEXT: ret i1 [[RET]] 399; 400; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 401; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@wrapper 402; IS__CGSCC_NPM-SAME: (i32 noundef [[C:%.*]]) #[[ATTR1]] { 403; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = call i1 @cmp_with_four(i32 noundef [[C]]) #[[ATTR2]] 404; IS__CGSCC_NPM-NEXT: ret i1 [[RET]] 405; 406 %ret = call i1 @cmp_with_four(i32 %c) 407 ret i1 %ret 408} 409 410define i1 @potential_test8() { 411; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 412; IS__TUNIT____-LABEL: define {{[^@]+}}@potential_test8 413; IS__TUNIT____-SAME: () #[[ATTR0]] { 414; IS__TUNIT____-NEXT: ret i1 false 415; 416; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 417; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test8 418; IS__CGSCC_OPM-SAME: () #[[ATTR1]] { 419; IS__CGSCC_OPM-NEXT: [[RES1:%.*]] = call i1 @wrapper(i32 noundef 1) #[[ATTR3]] 420; IS__CGSCC_OPM-NEXT: [[RES3:%.*]] = call i1 @wrapper(i32 noundef 3) #[[ATTR3]] 421; IS__CGSCC_OPM-NEXT: [[RES5:%.*]] = call i1 @wrapper(i32 noundef 5) #[[ATTR3]] 422; IS__CGSCC_OPM-NEXT: [[RES13:%.*]] = or i1 [[RES1]], [[RES3]] 423; IS__CGSCC_OPM-NEXT: [[RES135:%.*]] = or i1 [[RES13]], [[RES5]] 424; IS__CGSCC_OPM-NEXT: ret i1 [[RES135]] 425; 426; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 427; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test8 428; IS__CGSCC_NPM-SAME: () #[[ATTR1]] { 429; IS__CGSCC_NPM-NEXT: [[RES1:%.*]] = call i1 @wrapper(i32 noundef 1) #[[ATTR2]] 430; IS__CGSCC_NPM-NEXT: [[RES3:%.*]] = call i1 @wrapper(i32 noundef 3) #[[ATTR2]] 431; IS__CGSCC_NPM-NEXT: [[RES5:%.*]] = call i1 @wrapper(i32 noundef 5) #[[ATTR2]] 432; IS__CGSCC_NPM-NEXT: [[RES13:%.*]] = or i1 [[RES1]], [[RES3]] 433; IS__CGSCC_NPM-NEXT: [[RES135:%.*]] = or i1 [[RES13]], [[RES5]] 434; IS__CGSCC_NPM-NEXT: ret i1 [[RES135]] 435; 436 %res1 = call i1 @wrapper(i32 1) 437 %res3 = call i1 @wrapper(i32 3) 438 %res5 = call i1 @wrapper(i32 5) 439 %res13 = or i1 %res1, %res3 440 %res135 = or i1 %res13, %res5 441 ret i1 %res135 442} 443 444define i1 @potential_test9() { 445; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone 446; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test9 447; IS__TUNIT_OPM-SAME: () #[[ATTR1:[0-9]+]] { 448; IS__TUNIT_OPM-NEXT: entry: 449; IS__TUNIT_OPM-NEXT: br label [[COND:%.*]] 450; IS__TUNIT_OPM: cond: 451; IS__TUNIT_OPM-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_1:%.*]], [[INC:%.*]] ] 452; IS__TUNIT_OPM-NEXT: [[C_0:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[C_1:%.*]], [[INC]] ] 453; IS__TUNIT_OPM-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], 10 454; IS__TUNIT_OPM-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]] 455; IS__TUNIT_OPM: body: 456; IS__TUNIT_OPM-NEXT: [[C_1]] = mul i32 [[C_0]], -1 457; IS__TUNIT_OPM-NEXT: br label [[INC]] 458; IS__TUNIT_OPM: inc: 459; IS__TUNIT_OPM-NEXT: [[I_1]] = add i32 [[I_0]], 1 460; IS__TUNIT_OPM-NEXT: br label [[COND]] 461; IS__TUNIT_OPM: end: 462; IS__TUNIT_OPM-NEXT: ret i1 false 463; 464; IS________NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 465; IS________NPM-LABEL: define {{[^@]+}}@potential_test9 466; IS________NPM-SAME: () #[[ATTR0]] { 467; IS________NPM-NEXT: entry: 468; IS________NPM-NEXT: br label [[COND:%.*]] 469; IS________NPM: cond: 470; IS________NPM-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_1:%.*]], [[INC:%.*]] ] 471; IS________NPM-NEXT: [[C_0:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[C_1:%.*]], [[INC]] ] 472; IS________NPM-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], 10 473; IS________NPM-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]] 474; IS________NPM: body: 475; IS________NPM-NEXT: [[C_1]] = mul i32 [[C_0]], -1 476; IS________NPM-NEXT: br label [[INC]] 477; IS________NPM: inc: 478; IS________NPM-NEXT: [[I_1]] = add i32 [[I_0]], 1 479; IS________NPM-NEXT: br label [[COND]] 480; IS________NPM: end: 481; IS________NPM-NEXT: ret i1 false 482; 483; IS__CGSCC_OPM: Function Attrs: nofree norecurse nosync nounwind readnone 484; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test9 485; IS__CGSCC_OPM-SAME: () #[[ATTR2:[0-9]+]] { 486; IS__CGSCC_OPM-NEXT: entry: 487; IS__CGSCC_OPM-NEXT: br label [[COND:%.*]] 488; IS__CGSCC_OPM: cond: 489; IS__CGSCC_OPM-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_1:%.*]], [[INC:%.*]] ] 490; IS__CGSCC_OPM-NEXT: [[C_0:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[C_1:%.*]], [[INC]] ] 491; IS__CGSCC_OPM-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], 10 492; IS__CGSCC_OPM-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]] 493; IS__CGSCC_OPM: body: 494; IS__CGSCC_OPM-NEXT: [[C_1]] = mul i32 [[C_0]], -1 495; IS__CGSCC_OPM-NEXT: br label [[INC]] 496; IS__CGSCC_OPM: inc: 497; IS__CGSCC_OPM-NEXT: [[I_1]] = add i32 [[I_0]], 1 498; IS__CGSCC_OPM-NEXT: br label [[COND]] 499; IS__CGSCC_OPM: end: 500; IS__CGSCC_OPM-NEXT: ret i1 false 501; 502entry: 503 br label %cond 504cond: 505 %i.0 = phi i32 [0, %entry], [%i.1, %inc] 506 %c.0 = phi i32 [1, %entry], [%c.1, %inc] 507 %cmp = icmp slt i32 %i.0, 10 508 br i1 %cmp, label %body, label %end 509body: 510 %c.1 = mul i32 %c.0, -1 511 br label %inc 512inc: 513 %i.1 = add i32 %i.0, 1 514 br label %cond 515end: 516 %ret = icmp eq i32 %c.0, 0 517 ret i1 %ret 518} 519 520; Test 10 521; FIXME: potential returned values of @may_return_undef is {1, -1} 522; and returned value of @potential_test10 can be simplified to 0(false) 523 524define internal i32 @may_return_undef(i32 %c) { 525; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 526; IS__CGSCC____-LABEL: define {{[^@]+}}@may_return_undef 527; IS__CGSCC____-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 528; IS__CGSCC____-NEXT: switch i32 [[C]], label [[OTHERWISE:%.*]] [ 529; IS__CGSCC____-NEXT: i32 1, label [[A:%.*]] 530; IS__CGSCC____-NEXT: i32 -1, label [[B:%.*]] 531; IS__CGSCC____-NEXT: ] 532; IS__CGSCC____: a: 533; IS__CGSCC____-NEXT: ret i32 1 534; IS__CGSCC____: b: 535; IS__CGSCC____-NEXT: ret i32 -1 536; IS__CGSCC____: otherwise: 537; IS__CGSCC____-NEXT: ret i32 undef 538; 539 switch i32 %c, label %otherwise [i32 1, label %a 540 i32 -1, label %b] 541a: 542 ret i32 1 543b: 544 ret i32 -1 545otherwise: 546 ret i32 undef 547} 548 549define i1 @potential_test10(i32 %c) { 550; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 551; IS__TUNIT____-LABEL: define {{[^@]+}}@potential_test10 552; IS__TUNIT____-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 553; IS__TUNIT____-NEXT: ret i1 false 554; 555; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 556; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test10 557; IS__CGSCC_OPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 558; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = call i32 @may_return_undef(i32 [[C]]) #[[ATTR3]] 559; IS__CGSCC_OPM-NEXT: [[CMP:%.*]] = icmp eq i32 [[RET]], 0 560; IS__CGSCC_OPM-NEXT: ret i1 [[CMP]] 561; 562; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 563; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test10 564; IS__CGSCC_NPM-SAME: (i32 [[C:%.*]]) #[[ATTR1]] { 565; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = call i32 @may_return_undef(i32 [[C]]) #[[ATTR2]] 566; IS__CGSCC_NPM-NEXT: [[CMP:%.*]] = icmp eq i32 [[RET]], 0 567; IS__CGSCC_NPM-NEXT: ret i1 [[CMP]] 568; 569 %ret = call i32 @may_return_undef(i32 %c) 570 %cmp = icmp eq i32 %ret, 0 571 ret i1 %cmp 572} 573 574define i32 @optimize_undef_1(i1 %c) { 575; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 576; CHECK-LABEL: define {{[^@]+}}@optimize_undef_1 577; CHECK-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 578; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 579; CHECK: t: 580; CHECK-NEXT: ret i32 0 581; CHECK: f: 582; CHECK-NEXT: ret i32 1 583; 584 br i1 %c, label %t, label %f 585t: 586 ret i32 0 587f: 588 %undef = add i32 undef, 1 589 ret i32 %undef 590} 591 592define i32 @optimize_undef_2(i1 %c) { 593; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 594; CHECK-LABEL: define {{[^@]+}}@optimize_undef_2 595; CHECK-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 596; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 597; CHECK: t: 598; CHECK-NEXT: ret i32 0 599; CHECK: f: 600; CHECK-NEXT: ret i32 -1 601; 602 br i1 %c, label %t, label %f 603t: 604 ret i32 0 605f: 606 %undef = sub i32 undef, 1 607 ret i32 %undef 608} 609 610define i32 @optimize_undef_3(i1 %c) { 611; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 612; CHECK-LABEL: define {{[^@]+}}@optimize_undef_3 613; CHECK-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 614; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 615; CHECK: t: 616; CHECK-NEXT: ret i32 0 617; CHECK: f: 618; CHECK-NEXT: ret i32 1 619; 620 br i1 %c, label %t, label %f 621t: 622 ret i32 0 623f: 624 %undef = icmp eq i32 undef, 0 625 %undef2 = zext i1 %undef to i32 626 ret i32 %undef2 627} 628 629 630; FIXME: returned value can be simplified to 0 631define i32 @potential_test11(i1 %c) { 632; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 633; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test11 634; IS__TUNIT_OPM-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 635; IS__TUNIT_OPM-NEXT: [[ZERO1:%.*]] = call i32 @optimize_undef_1(i1 [[C]]) #[[ATTR2]], !range [[RNG2:![0-9]+]] 636; IS__TUNIT_OPM-NEXT: [[ZERO2:%.*]] = call i32 @optimize_undef_2(i1 [[C]]) #[[ATTR2]], !range [[RNG3:![0-9]+]] 637; IS__TUNIT_OPM-NEXT: [[ZERO3:%.*]] = call i32 @optimize_undef_3(i1 [[C]]) #[[ATTR2]], !range [[RNG2]] 638; IS__TUNIT_OPM-NEXT: [[ACC1:%.*]] = add i32 [[ZERO1]], [[ZERO2]] 639; IS__TUNIT_OPM-NEXT: [[ACC2:%.*]] = add i32 [[ACC1]], [[ZERO3]] 640; IS__TUNIT_OPM-NEXT: ret i32 [[ACC2]] 641; 642; IS__TUNIT_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 643; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@potential_test11 644; IS__TUNIT_NPM-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 645; IS__TUNIT_NPM-NEXT: [[ZERO1:%.*]] = call i32 @optimize_undef_1(i1 [[C]]) #[[ATTR1]], !range [[RNG2:![0-9]+]] 646; IS__TUNIT_NPM-NEXT: [[ZERO2:%.*]] = call i32 @optimize_undef_2(i1 [[C]]) #[[ATTR1]], !range [[RNG3:![0-9]+]] 647; IS__TUNIT_NPM-NEXT: [[ZERO3:%.*]] = call i32 @optimize_undef_3(i1 [[C]]) #[[ATTR1]], !range [[RNG2]] 648; IS__TUNIT_NPM-NEXT: [[ACC1:%.*]] = add i32 [[ZERO1]], [[ZERO2]] 649; IS__TUNIT_NPM-NEXT: [[ACC2:%.*]] = add i32 [[ACC1]], [[ZERO3]] 650; IS__TUNIT_NPM-NEXT: ret i32 [[ACC2]] 651; 652; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 653; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test11 654; IS__CGSCC_OPM-SAME: (i1 [[C:%.*]]) #[[ATTR1]] { 655; IS__CGSCC_OPM-NEXT: [[ZERO1:%.*]] = call i32 @optimize_undef_1(i1 [[C]]) #[[ATTR3]] 656; IS__CGSCC_OPM-NEXT: [[ZERO2:%.*]] = call i32 @optimize_undef_2(i1 [[C]]) #[[ATTR3]] 657; IS__CGSCC_OPM-NEXT: [[ZERO3:%.*]] = call i32 @optimize_undef_3(i1 [[C]]) #[[ATTR3]] 658; IS__CGSCC_OPM-NEXT: [[ACC1:%.*]] = add i32 [[ZERO1]], [[ZERO2]] 659; IS__CGSCC_OPM-NEXT: [[ACC2:%.*]] = add i32 [[ACC1]], [[ZERO3]] 660; IS__CGSCC_OPM-NEXT: ret i32 [[ACC2]] 661; 662; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 663; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test11 664; IS__CGSCC_NPM-SAME: (i1 [[C:%.*]]) #[[ATTR1]] { 665; IS__CGSCC_NPM-NEXT: [[ZERO1:%.*]] = call i32 @optimize_undef_1(i1 [[C]]) #[[ATTR2]] 666; IS__CGSCC_NPM-NEXT: [[ZERO2:%.*]] = call i32 @optimize_undef_2(i1 [[C]]) #[[ATTR2]] 667; IS__CGSCC_NPM-NEXT: [[ZERO3:%.*]] = call i32 @optimize_undef_3(i1 [[C]]) #[[ATTR2]] 668; IS__CGSCC_NPM-NEXT: [[ACC1:%.*]] = add i32 [[ZERO1]], [[ZERO2]] 669; IS__CGSCC_NPM-NEXT: [[ACC2:%.*]] = add i32 [[ACC1]], [[ZERO3]] 670; IS__CGSCC_NPM-NEXT: ret i32 [[ACC2]] 671; 672 %zero1 = call i32 @optimize_undef_1(i1 %c) 673 %zero2 = call i32 @optimize_undef_2(i1 %c) 674 %zero3 = call i32 @optimize_undef_3(i1 %c) 675 %acc1 = add i32 %zero1, %zero2 676 %acc2 = add i32 %acc1, %zero3 677 ret i32 %acc2 678} 679 680define i32 @optimize_poison_1(i1 %c) { 681; IS________OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 682; IS________OPM-LABEL: define {{[^@]+}}@optimize_poison_1 683; IS________OPM-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 684; IS________OPM-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 685; IS________OPM: t: 686; IS________OPM-NEXT: ret i32 0 687; IS________OPM: f: 688; IS________OPM-NEXT: ret i32 -1 689; 690; IS________NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 691; IS________NPM-LABEL: define {{[^@]+}}@optimize_poison_1 692; IS________NPM-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 693; IS________NPM-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 694; IS________NPM: t: 695; IS________NPM-NEXT: ret i32 0 696; IS________NPM: f: 697; IS________NPM-NEXT: ret i32 undef 698; 699 br i1 %c, label %t, label %f 700t: 701 ret i32 0 702f: 703 %poison = sub nuw i32 0, 1 704 ret i32 %poison 705} 706 707; FIXME: returned value can be simplified to 0 708define i32 @potential_test12(i1 %c) { 709; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 710; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test12 711; IS__TUNIT_OPM-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 712; IS__TUNIT_OPM-NEXT: [[ZERO:%.*]] = call noundef i32 @optimize_poison_1(i1 [[C]]) #[[ATTR2]], !range [[RNG3]] 713; IS__TUNIT_OPM-NEXT: ret i32 [[ZERO]] 714; 715; IS__TUNIT_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 716; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@potential_test12 717; IS__TUNIT_NPM-SAME: (i1 [[C:%.*]]) #[[ATTR0]] { 718; IS__TUNIT_NPM-NEXT: ret i32 0 719; 720; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 721; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test12 722; IS__CGSCC_OPM-SAME: (i1 [[C:%.*]]) #[[ATTR1]] { 723; IS__CGSCC_OPM-NEXT: [[ZERO:%.*]] = call noundef i32 @optimize_poison_1(i1 [[C]]) #[[ATTR3]] 724; IS__CGSCC_OPM-NEXT: ret i32 [[ZERO]] 725; 726; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 727; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test12 728; IS__CGSCC_NPM-SAME: (i1 [[C:%.*]]) #[[ATTR1]] { 729; IS__CGSCC_NPM-NEXT: [[ZERO:%.*]] = call noundef i32 @optimize_poison_1(i1 [[C]]) #[[ATTR2]] 730; IS__CGSCC_NPM-NEXT: ret i32 [[ZERO]] 731; 732 %zero = call i32 @optimize_poison_1(i1 %c) 733 ret i32 %zero 734} 735 736; Test 13 737; Do not simplify %ret in the callee to `%c`. 738; The potential value of %c is {0, 1} (undef is merged). 739; However, we should not simplify `and i32 %c, 3` to `%c` 740 741define internal i32 @potential_test13_callee(i32 %c) { 742; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 743; CHECK-LABEL: define {{[^@]+}}@potential_test13_callee 744; CHECK-SAME: (i32 [[C:%.*]]) #[[ATTR0]] { 745; CHECK-NEXT: [[RET:%.*]] = and i32 [[C]], 3 746; CHECK-NEXT: ret i32 [[RET]] 747; 748 %ret = and i32 %c, 3 749 ret i32 %ret 750} 751 752define i32 @potential_test13_caller1() { 753; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 754; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test13_caller1 755; IS__TUNIT_OPM-SAME: () #[[ATTR0]] { 756; IS__TUNIT_OPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 0) #[[ATTR2]], !range [[RNG2]] 757; IS__TUNIT_OPM-NEXT: ret i32 [[RET]] 758; 759; IS__TUNIT_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 760; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@potential_test13_caller1 761; IS__TUNIT_NPM-SAME: () #[[ATTR0]] { 762; IS__TUNIT_NPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 0) #[[ATTR1]], !range [[RNG2]] 763; IS__TUNIT_NPM-NEXT: ret i32 [[RET]] 764; 765; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 766; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test13_caller1 767; IS__CGSCC_OPM-SAME: () #[[ATTR1]] { 768; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 0) #[[ATTR3]] 769; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 770; 771; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 772; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test13_caller1 773; IS__CGSCC_NPM-SAME: () #[[ATTR1]] { 774; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 0) #[[ATTR2]] 775; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 776; 777 %ret = call i32 @potential_test13_callee(i32 0) 778 ret i32 %ret 779} 780 781define i32 @potential_test13_caller2() { 782; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 783; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test13_caller2 784; IS__TUNIT_OPM-SAME: () #[[ATTR0]] { 785; IS__TUNIT_OPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 1) #[[ATTR2]], !range [[RNG2]] 786; IS__TUNIT_OPM-NEXT: ret i32 [[RET]] 787; 788; IS__TUNIT_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 789; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@potential_test13_caller2 790; IS__TUNIT_NPM-SAME: () #[[ATTR0]] { 791; IS__TUNIT_NPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 1) #[[ATTR1]], !range [[RNG2]] 792; IS__TUNIT_NPM-NEXT: ret i32 [[RET]] 793; 794; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 795; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test13_caller2 796; IS__CGSCC_OPM-SAME: () #[[ATTR1]] { 797; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 1) #[[ATTR3]] 798; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 799; 800; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 801; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test13_caller2 802; IS__CGSCC_NPM-SAME: () #[[ATTR1]] { 803; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 noundef 1) #[[ATTR2]] 804; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 805; 806 %ret = call i32 @potential_test13_callee(i32 1) 807 ret i32 %ret 808} 809 810define i32 @potential_test13_caller3() { 811; IS__TUNIT_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 812; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@potential_test13_caller3 813; IS__TUNIT_OPM-SAME: () #[[ATTR0]] { 814; IS__TUNIT_OPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 undef) #[[ATTR2]], !range [[RNG2]] 815; IS__TUNIT_OPM-NEXT: ret i32 [[RET]] 816; 817; IS__TUNIT_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 818; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@potential_test13_caller3 819; IS__TUNIT_NPM-SAME: () #[[ATTR0]] { 820; IS__TUNIT_NPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 undef) #[[ATTR1]], !range [[RNG2]] 821; IS__TUNIT_NPM-NEXT: ret i32 [[RET]] 822; 823; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn 824; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@potential_test13_caller3 825; IS__CGSCC_OPM-SAME: () #[[ATTR1]] { 826; IS__CGSCC_OPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 undef) #[[ATTR3]] 827; IS__CGSCC_OPM-NEXT: ret i32 [[RET]] 828; 829; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn 830; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@potential_test13_caller3 831; IS__CGSCC_NPM-SAME: () #[[ATTR1]] { 832; IS__CGSCC_NPM-NEXT: [[RET:%.*]] = call i32 @potential_test13_callee(i32 undef) #[[ATTR2]] 833; IS__CGSCC_NPM-NEXT: ret i32 [[RET]] 834; 835 %ret = call i32 @potential_test13_callee(i32 undef) 836 ret i32 %ret 837} 838 839define i1 @potential_test14(i1 %c0, i1 %c1, i1 %c2, i1 %c3) { 840; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 841; CHECK-LABEL: define {{[^@]+}}@potential_test14 842; CHECK-SAME: (i1 [[C0:%.*]], i1 [[C1:%.*]], i1 [[C2:%.*]], i1 [[C3:%.*]]) #[[ATTR0]] { 843; CHECK-NEXT: [[X0:%.*]] = select i1 [[C0]], i32 0, i32 1 844; CHECK-NEXT: [[X1:%.*]] = select i1 [[C1]], i32 [[X0]], i32 undef 845; CHECK-NEXT: [[Y2:%.*]] = select i1 [[C2]], i32 0, i32 7 846; CHECK-NEXT: [[Z3:%.*]] = select i1 [[C3]], i32 [[X1]], i32 [[Y2]] 847; CHECK-NEXT: [[RET:%.*]] = icmp slt i32 [[Z3]], 7 848; CHECK-NEXT: ret i1 [[RET]] 849; 850 %x0 = select i1 %c0, i32 0, i32 1 851 %x1 = select i1 %c1, i32 %x0, i32 undef 852 %y2 = select i1 %c2, i32 0, i32 7 853 %z3 = select i1 %c3, i32 %x1, i32 %y2 854 %ret = icmp slt i32 %z3, 7 855 ret i1 %ret 856} 857 858define i1 @potential_test15(i1 %c0, i1 %c1) { 859; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 860; CHECK-LABEL: define {{[^@]+}}@potential_test15 861; CHECK-SAME: (i1 [[C0:%.*]], i1 [[C1:%.*]]) #[[ATTR0]] { 862; CHECK-NEXT: ret i1 false 863; 864 %x0 = select i1 %c0, i32 0, i32 1 865 %x1 = select i1 %c1, i32 %x0, i32 undef 866 %ret = icmp eq i32 %x1, 7 867 ret i1 %ret 868} 869 870define i1 @potential_test16(i1 %c0, i1 %c1) { 871; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 872; CHECK-LABEL: define {{[^@]+}}@potential_test16 873; CHECK-SAME: (i1 [[C0:%.*]], i1 [[C1:%.*]]) #[[ATTR0]] { 874; CHECK-NEXT: ret i1 false 875; 876 %x0 = select i1 %c0, i32 0, i32 undef 877 %x1 = select i1 %c1, i32 %x0, i32 1 878 %ret = icmp eq i32 %x1, 7 879 ret i1 %ret 880} 881 882;. 883; IS__TUNIT_OPM: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn } 884; IS__TUNIT_OPM: attributes #[[ATTR1]] = { nofree norecurse nosync nounwind readnone } 885; IS__TUNIT_OPM: attributes #[[ATTR2]] = { nofree nosync nounwind readnone willreturn } 886;. 887; IS__TUNIT_NPM: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn } 888; IS__TUNIT_NPM: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn } 889;. 890; IS__CGSCC_OPM: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn } 891; IS__CGSCC_OPM: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn } 892; IS__CGSCC_OPM: attributes #[[ATTR2]] = { nofree norecurse nosync nounwind readnone } 893; IS__CGSCC_OPM: attributes #[[ATTR3]] = { readnone willreturn } 894;. 895; IS__CGSCC_NPM: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn } 896; IS__CGSCC_NPM: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn } 897; IS__CGSCC_NPM: attributes #[[ATTR2]] = { readnone willreturn } 898;. 899; IS__TUNIT____: [[META0:![0-9]+]] = !{i32 1, i32 4} 900; IS__TUNIT____: [[META1:![0-9]+]] = !{i32 3, i32 5} 901; IS__TUNIT____: [[META2:![0-9]+]] = !{i32 0, i32 2} 902; IS__TUNIT____: [[META3:![0-9]+]] = !{i32 -1, i32 1} 903;. 904