diff --git a/llvm/include/llvm/Analysis/ConstraintSystem.h b/llvm/include/llvm/Analysis/ConstraintSystem.h --- a/llvm/include/llvm/Analysis/ConstraintSystem.h +++ b/llvm/include/llvm/Analysis/ConstraintSystem.h @@ -13,13 +13,14 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Casting.h" #include namespace llvm { class Value; - +class Argument; class ConstraintSystem { struct Entry { int64_t Coefficient; @@ -68,8 +69,16 @@ public: ConstraintSystem() {} + ConstraintSystem(SmallVector FunctionArgs) { + NumVariables += FunctionArgs.size(); + for (Value *Arg : FunctionArgs) { + Value2Index.insert({Arg, Value2Index.size() + 1}); + } + } ConstraintSystem(const DenseMap &Value2Index) - : Value2Index(Value2Index) {} + : Value2Index(Value2Index) { + NumVariables = Value2Index.size(); + } bool addVariableRow(ArrayRef R) { assert(Constraints.empty() || R.size() == NumVariables); diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -138,7 +138,11 @@ const DataLayout &DL; public: - ConstraintInfo(const DataLayout &DL) : DL(DL) {} + ConstraintInfo(const DataLayout &DL, SmallVector FunctionArgs) + : DL(DL) { + UnsignedCS = ConstraintSystem(FunctionArgs); + SignedCS = ConstraintSystem(FunctionArgs); + } DenseMap &getValue2Index(bool Signed) { return Signed ? SignedCS.getValue2Index() : UnsignedCS.getValue2Index(); @@ -1162,8 +1166,11 @@ OptimizationRemarkEmitter &ORE) { bool Changed = false; DT.updateDFSNumbers(); + SmallVector FunctionArgs; + for (Value &Arg : F.args()) + FunctionArgs.push_back(&Arg); - ConstraintInfo Info(F.getParent()->getDataLayout()); + ConstraintInfo Info(F.getParent()->getDataLayout(), FunctionArgs); State S(DT); std::unique_ptr ReproducerModule( DumpReproducers ? new Module(F.getName(), F.getContext()) : nullptr); diff --git a/llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll b/llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll --- a/llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll +++ b/llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll @@ -295,8 +295,6 @@ ret i1 1 } -; TODO: Even though %cnt is not known signed positive %cmp can be simplified -; because %add.ptr uses it zero-extended. define i1 @cnt_not_known_positive_sgt_against_base_with_zext(ptr %p, i32 %cnt) { ; CHECK-LABEL: @cnt_not_known_positive_sgt_against_base_with_zext( ; CHECK-NEXT: entry: @@ -305,7 +303,7 @@ ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[CNT]] to i64 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[P:%.*]], i64 [[EXT]] ; CHECK-NEXT: [[CMP_1:%.*]] = icmp uge ptr [[ADD_PTR]], [[P]] -; CHECK-NEXT: br i1 [[CMP_1]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK-NEXT: br i1 true, label [[THEN:%.*]], label [[ELSE:%.*]] ; CHECK: then: ; CHECK-NEXT: ret i1 false ; CHECK: else: @@ -326,8 +324,6 @@ ret i1 1 } -; TODO: Even though %cnt is not known signed positive %cmp can be simplified -; because %add.ptr uses it zero-extended. define i1 @cnt_not_known_positive_sge_against_base_with_zext(ptr %p, i32 %cnt) { ; CHECK-LABEL: @cnt_not_known_positive_sge_against_base_with_zext( ; CHECK-NEXT: entry: @@ -336,7 +332,7 @@ ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[CNT]] to i64 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[P:%.*]], i64 [[EXT]] ; CHECK-NEXT: [[CMP_1:%.*]] = icmp uge ptr [[ADD_PTR]], [[P]] -; CHECK-NEXT: br i1 [[CMP_1]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK-NEXT: br i1 true, label [[THEN:%.*]], label [[ELSE:%.*]] ; CHECK: then: ; CHECK-NEXT: ret i1 false ; CHECK: else: @@ -453,7 +449,6 @@ ret i1 1 } -; TODO: Even though %cnt is not known signed positive %cmp can be simplified ; because %add.ptr uses it zero-extended. define i1 @cnt_not_known_positive_from_branch_check_against_base_struct_ugt_with_zext(ptr %p, i32 %cnt) { ; CHECK-LABEL: @cnt_not_known_positive_from_branch_check_against_base_struct_ugt_with_zext( @@ -464,7 +459,7 @@ ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[CNT]] to i64 ; CHECK-NEXT: [[GEP_EXT:%.*]] = getelementptr inbounds [[T:%.*]], ptr [[P:%.*]], i64 0, i32 1, i64 [[EXT]] ; CHECK-NEXT: [[CMP_1:%.*]] = icmp ugt ptr [[GEP_EXT]], [[P]] -; CHECK-NEXT: br i1 [[CMP_1]], label [[THEN:%.*]], label [[ELSE]] +; CHECK-NEXT: br i1 true, label [[THEN:%.*]], label [[ELSE]] ; CHECK: then: ; CHECK-NEXT: ret i1 false ; CHECK: else: diff --git a/llvm/test/Transforms/ConstraintElimination/type-bounds.ll b/llvm/test/Transforms/ConstraintElimination/type-bounds.ll --- a/llvm/test/Transforms/ConstraintElimination/type-bounds.ll +++ b/llvm/test/Transforms/ConstraintElimination/type-bounds.ll @@ -45,7 +45,7 @@ ; CHECK-NEXT: br i1 [[CMP_1]], label [[COND:%.*]], label [[EXIT:%.*]] ; CHECK: cond: ; CHECK-NEXT: [[CMP_2:%.*]] = icmp ult i32 [[A_EXT]], [[B]] -; CHECK-NEXT: call void @use(i1 [[CMP_2]]) +; CHECK-NEXT: call void @use(i1 true) ; CHECK-NEXT: ret void ; CHECK: exit: ; CHECK-NEXT: ret void @@ -314,7 +314,7 @@ ; CHECK-NEXT: br i1 [[CMP_1]], label [[COND:%.*]], label [[EXIT:%.*]] ; CHECK: cond: ; CHECK-NEXT: [[CMP_2:%.*]] = icmp ult i32 [[ADD_EXT]], [[C]] -; CHECK-NEXT: call void @use(i1 [[CMP_2]]) +; CHECK-NEXT: call void @use(i1 true) ; CHECK-NEXT: ret void ; CHECK: exit: ; CHECK-NEXT: ret void