File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -1768,7 +1768,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
17681768 Constant *C2;
17691769
17701770 // C-(C2-X) --> X+(C-C2)
1771- if (match (Op1, m_Sub (m_Constant (C2), m_Value (X))))
1771+ if (match (Op1, m_Sub (m_Constant (C2), m_Value (X))) && !isa<ConstantExpr>(C2) )
17721772 return BinaryOperator::CreateAdd (X, ConstantExpr::getSub (C, C2));
17731773
17741774 // C-(X+C2) --> (C-C2)-X
Original file line number Diff line number Diff line change @@ -569,3 +569,21 @@ define i1 @abs_must_be_positive(i32 %x) {
569569 ret i1 %c2
570570}
571571
572+ @g = external global i64
573+
574+ ; PR45539 - https://bugs.llvm.org/show_bug.cgi?id=45539
575+
576+ define i64 @infinite_loop_constant_expression_abs (i64 %arg ) {
577+ ; CHECK-LABEL: @infinite_loop_constant_expression_abs(
578+ ; CHECK-NEXT: [[T:%.*]] = sub i64 ptrtoint (i64* @g to i64), [[ARG:%.*]]
579+ ; CHECK-NEXT: [[T1:%.*]] = icmp slt i64 [[T]], 0
580+ ; CHECK-NEXT: [[T2:%.*]] = sub nsw i64 0, [[T]]
581+ ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T1]], i64 [[T2]], i64 [[T]]
582+ ; CHECK-NEXT: ret i64 [[T3]]
583+ ;
584+ %t = sub i64 ptrtoint (i64* @g to i64 ), %arg
585+ %t1 = icmp slt i64 %t , 0
586+ %t2 = sub nsw i64 0 , %t
587+ %t3 = select i1 %t1 , i64 %t2 , i64 %t
588+ ret i64 %t3
589+ }
You can’t perform that action at this time.
0 commit comments