Skip to content

Commit 8e3e962

Browse files
committed
[ConstraintElimination] Order cmps for signed <-> unsigned transfer first.
Make sure conditions with constant operands come before conditions without constant operands. This increases the effectiveness of the current signed <-> unsigned fact transfer logic.
1 parent cbbf1eb commit 8e3e962

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,20 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
757757
// Next, sort worklist by dominance, so that dominating blocks and conditions
758758
// come before blocks and conditions dominated by them. If a block and a
759759
// condition have the same numbers, the condition comes before the block, as
760-
// it holds on entry to the block.
761-
stable_sort(S.WorkList, [](const ConstraintOrBlock &A, const ConstraintOrBlock &B) {
762-
return std::tie(A.NumIn, A.IsBlock) < std::tie(B.NumIn, B.IsBlock);
763-
});
760+
// it holds on entry to the block. Also make sure conditions with constant
761+
// operands come before conditions without constant operands. This increases
762+
// the effectiveness of the current signed <-> unsigned fact transfer logic.
763+
stable_sort(
764+
S.WorkList, [](const ConstraintOrBlock &A, const ConstraintOrBlock &B) {
765+
auto HasNoConstOp = [](const ConstraintOrBlock &B) {
766+
return !B.IsBlock && !isa<ConstantInt>(B.Condition->getOperand(0)) &&
767+
!isa<ConstantInt>(B.Condition->getOperand(1));
768+
};
769+
bool NoConstOpA = HasNoConstOp(A);
770+
bool NoConstOpB = HasNoConstOp(B);
771+
return std::tie(A.NumIn, A.IsBlock, NoConstOpA) <
772+
std::tie(B.NumIn, B.IsBlock, NoConstOpB);
773+
});
764774

765775
SmallVector<Instruction *> ToRemove;
766776

llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ define i1 @len_known_positive_via_idx_2(i8 %len, i8 %idx) {
5353
; CHECK-NEXT: [[T_2:%.*]] = icmp sge i8 [[LEN]], 0
5454
; CHECK-NEXT: [[C_1:%.*]] = icmp sge i8 [[LEN]], 2
5555
; CHECK-NEXT: [[C_2:%.*]] = icmp sge i8 [[LEN]], 2
56-
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[T_1]], true
56+
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, true
5757
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_1]]
5858
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[RES_2]], [[C_2]]
5959
; CHECK-NEXT: ret i1 [[RES_3]]

llvm/test/Transforms/ConstraintElimination/transfer-unsigned-facts-to-signed.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ define i1 @idx_known_positive_via_len_2(i8 %len, i8 %idx) {
5555
; CHECK: then.1:
5656
; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[IDX]], [[LEN]]
5757
; CHECK-NEXT: [[T_2:%.*]] = icmp sge i8 [[IDX]], 0
58-
; CHECK-NEXT: [[R_1:%.*]] = xor i1 true, [[T_2]]
58+
; CHECK-NEXT: [[R_1:%.*]] = xor i1 true, true
5959
; CHECK-NEXT: [[C_1:%.*]] = icmp sge i8 [[IDX]], 1
6060
; CHECK-NEXT: [[R_2:%.*]] = xor i1 [[R_1]], [[C_1]]
6161
; CHECK-NEXT: [[C_2:%.*]] = icmp sge i8 [[LEN]], 1
62-
; CHECK-NEXT: [[R_3:%.*]] = xor i1 [[R_2]], [[C_2]]
62+
; CHECK-NEXT: [[R_3:%.*]] = xor i1 [[R_2]], true
6363
; CHECK-NEXT: ret i1 [[R_3]]
6464
; CHECK: else:
6565
; CHECK-NEXT: [[C_3:%.*]] = icmp sge i8 [[IDX]], 0

0 commit comments

Comments
 (0)