ret i32 42
}
+declare void @use1(i1)
+define i32 @compare_against_fortytwo_commutatibility_0(i32 %x) {
+; CHECK-LABEL: @compare_against_fortytwo_commutatibility_0(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[X:%.*]], 42
+; CHECK-NEXT: br i1 [[TMP0]], label [[CALLFOO:%.*]], label [[EXIT:%.*]]
+; CHECK: callfoo:
+; CHECK-NEXT: call void @foo(i32 1)
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret i32 84
+;
+entry:
+ %cmp1 = icmp eq i32 %x, 42
+ %cmp2 = icmp slt i32 %x, 42
+ %select1 = select i1 %cmp2, i32 -1, i32 1
+ %select2 = select i1 %cmp1, i32 0, i32 %select1
+ %cond = icmp sgt i32 %select2, 0
+ br i1 %cond, label %callfoo, label %exit
+
+callfoo:
+ call void @foo(i32 %select2)
+ br label %exit
+
+exit:
+ ret i32 84
+}
+define i32 @compare_against_fortytwo_commutatibility_1(i32 %x) {
+; CHECK-LABEL: @compare_against_fortytwo_commutatibility_1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[X:%.*]], 42
+; CHECK-NEXT: call void @use1(i1 [[CMP1]])
+; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[X]], 42
+; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[CMP2]], i32 -1, i32 1
+; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP1]], i32 [[SELECT1]], i32 0
+; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[SELECT2]], 0
+; CHECK-NEXT: br i1 [[COND]], label [[CALLFOO:%.*]], label [[EXIT:%.*]]
+; CHECK: callfoo:
+; CHECK-NEXT: call void @foo(i32 [[SELECT2]])
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret i32 84
+;
+entry:
+ %cmp1 = icmp ne i32 %x, 42 ; inverted
+ call void @use1(i1 %cmp1)
+ %cmp2 = icmp slt i32 %x, 42
+ %select1 = select i1 %cmp2, i32 -1, i32 1
+ %select2 = select i1 %cmp1, i32 %select1, i32 0 ; swapped
+ %cond = icmp sgt i32 %select2, 0
+ br i1 %cond, label %callfoo, label %exit
+
+callfoo:
+ call void @foo(i32 %select2)
+ br label %exit
+
+exit:
+ ret i32 84
+}
+define i32 @compare_against_fortytwo_commutatibility_2(i32 %x) {
+; CHECK-LABEL: @compare_against_fortytwo_commutatibility_2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[X:%.*]], 42
+; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[X]], 41
+; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[CMP2]], i32 1, i32 -1
+; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP1]], i32 0, i32 [[SELECT1]]
+; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[SELECT2]], 0
+; CHECK-NEXT: br i1 [[COND]], label [[CALLFOO:%.*]], label [[EXIT:%.*]]
+; CHECK: callfoo:
+; CHECK-NEXT: call void @foo(i32 [[SELECT2]])
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret i32 84
+;
+entry:
+ %cmp1 = icmp eq i32 %x, 42
+ %cmp2 = icmp sgt i32 %x, 41 ; inverted
+ %select1 = select i1 %cmp2, i32 1, i32 -1 ; swapped
+ %select2 = select i1 %cmp1, i32 0, i32 %select1
+ %cond = icmp sgt i32 %select2, 0
+ br i1 %cond, label %callfoo, label %exit
+
+callfoo:
+ call void @foo(i32 %select2)
+ br label %exit
+
+exit:
+ ret i32 84
+}
+define i32 @compare_against_fortytwo_commutatibility_3(i32 %x) {
+; CHECK-LABEL: @compare_against_fortytwo_commutatibility_3(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[X:%.*]], 42
+; CHECK-NEXT: call void @use1(i1 [[CMP1]])
+; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[X]], 41
+; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[CMP2]], i32 1, i32 -1
+; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP1]], i32 [[SELECT1]], i32 0
+; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[SELECT2]], 0
+; CHECK-NEXT: br i1 [[COND]], label [[CALLFOO:%.*]], label [[EXIT:%.*]]
+; CHECK: callfoo:
+; CHECK-NEXT: call void @foo(i32 [[SELECT2]])
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret i32 84
+;
+entry:
+ %cmp1 = icmp ne i32 %x, 42 ; inverted
+ call void @use1(i1 %cmp1)
+ %cmp2 = icmp sgt i32 %x, 41 ; inverted
+ %select1 = select i1 %cmp2, i32 1, i32 -1 ; swapped
+ %select2 = select i1 %cmp1, i32 %select1, i32 0 ; swapped
+ %cond = icmp sgt i32 %select2, 0
+ br i1 %cond, label %callfoo, label %exit
+
+callfoo:
+ call void @foo(i32 %select2)
+ br label %exit
+
+exit:
+ ret i32 84
+}