namespace llvm {
class Value;
-
class ConstraintSystem {
struct Entry {
int64_t Coefficient;
public:
ConstraintSystem() {}
+ ConstraintSystem(ArrayRef<Value *> FunctionArgs) {
+ NumVariables += FunctionArgs.size();
+ for (auto *Arg : FunctionArgs) {
+ Value2Index.insert({Arg, Value2Index.size() + 1});
+ }
+ }
ConstraintSystem(const DenseMap<Value *, unsigned> &Value2Index)
- : Value2Index(Value2Index) {}
+ : NumVariables(Value2Index.size()), Value2Index(Value2Index) {}
bool addVariableRow(ArrayRef<int64_t> R) {
assert(Constraints.empty() || R.size() == NumVariables);
const DataLayout &DL;
public:
- ConstraintInfo(const DataLayout &DL) : DL(DL) {}
+ ConstraintInfo(const DataLayout &DL, ArrayRef<Value *> FunctionArgs)
+ : UnsignedCS(FunctionArgs), SignedCS(FunctionArgs), DL(DL) {}
DenseMap<Value *, unsigned> &getValue2Index(bool Signed) {
return Signed ? SignedCS.getValue2Index() : UnsignedCS.getValue2Index();
OptimizationRemarkEmitter &ORE) {
bool Changed = false;
DT.updateDFSNumbers();
-
- ConstraintInfo Info(F.getParent()->getDataLayout());
+ SmallVector<Value *> FunctionArgs;
+ for (Value &Arg : F.args())
+ FunctionArgs.push_back(&Arg);
+ ConstraintInfo Info(F.getParent()->getDataLayout(), FunctionArgs);
State S(DT);
std::unique_ptr<Module> ReproducerModule(
DumpReproducers ? new Module(F.getName(), F.getContext()) : nullptr);
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:
; 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:
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:
; 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:
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(
; 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: