@@ -382,3 +382,40 @@ exit: ; CVP only simplifies based on ranges for non-local conditions.
382382 call void @use (i1 %t.1 )
383383 ret i64 %res
384384}
385+
386+ ; Test case for PR68381.
387+ ; Because of `undef`, we can only delete the second `and` instruction.
388+ define i32 @constant_range_and_undef_and (i1 %c0 , i1 %c1 , i8 %v1 , i8 %v2 ) {
389+ ; CHECK-LABEL: @constant_range_and_undef_and(
390+ ; CHECK-NEXT: start:
391+ ; CHECK-NEXT: br i1 [[C0:%.*]], label [[BB0:%.*]], label [[BB1:%.*]]
392+ ; CHECK: bb0:
393+ ; CHECK-NEXT: [[V1_I32:%.*]] = zext i8 [[V1:%.*]] to i32
394+ ; CHECK-NEXT: br label [[BB1]]
395+ ; CHECK: bb1:
396+ ; CHECK-NEXT: [[X:%.*]] = phi i32 [ [[V1_I32]], [[BB0]] ], [ undef, [[START:%.*]] ]
397+ ; CHECK-NEXT: br i1 [[C1:%.*]], label [[BB0]], label [[BB2:%.*]]
398+ ; CHECK: bb2:
399+ ; CHECK-NEXT: [[V2_I32:%.*]] = zext i8 [[V2:%.*]] to i32
400+ ; CHECK-NEXT: [[Y:%.*]] = or i32 [[X]], [[V2_I32]]
401+ ; CHECK-NEXT: [[Z:%.*]] = and i32 [[Y]], 255
402+ ; CHECK-NEXT: ret i32 [[Z]]
403+ ;
404+ start:
405+ br i1 %c0 , label %bb0 , label %bb1
406+
407+ bb0:
408+ %v1_i32 = zext i8 %v1 to i32
409+ br label %bb1
410+
411+ bb1:
412+ %x = phi i32 [ %v1_i32 , %bb0 ], [ undef , %start ]
413+ br i1 %c1 , label %bb0 , label %bb2
414+
415+ bb2:
416+ %v2_i32 = zext i8 %v2 to i32
417+ %y = or i32 %x , %v2_i32
418+ %z = and i32 %y , 255
419+ %z1 = and i32 %z , 255
420+ ret i32 %z1
421+ }
0 commit comments