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 @@ -1758,7 +1758,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
1758
1758
Constant *C2;
1759
1759
1760
1760
// C-(C2-X) --> X+(C-C2)
1761
- if (match (Op1, m_Sub (m_Constant (C2), m_Value (X))))
1761
+ if (match (Op1, m_Sub (m_Constant (C2), m_Value (X))) && !isa<ConstantExpr>(C2) )
1762
1762
return BinaryOperator::CreateAdd (X, ConstantExpr::getSub (C, C2));
1763
1763
1764
1764
// 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) {
569
569
ret i1 %c2
570
570
}
571
571
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