File tree 2 files changed +20
-1
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -1761,7 +1761,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
1761
1761
Constant *C2;
1762
1762
1763
1763
// C-(C2-X) --> X+(C-C2)
1764
- if (match (Op1, m_Sub (m_Constant (C2), m_Value (X))))
1764
+ if (match (Op1, m_Sub (m_Constant (C2), m_Value (X))) && !isa<ConstantExpr>(C2) )
1765
1765
return BinaryOperator::CreateAdd (X, ConstantExpr::getSub (C, C2));
1766
1766
1767
1767
// C-(X+C2) --> (C-C2)-X
Original file line number Diff line number Diff line change @@ -628,3 +628,22 @@ define i8 @nabs_different_constants(i8 %a) {
628
628
%m2 = select i1 %cmp2 , i8 %neg , i8 %a
629
629
ret i8 %m2
630
630
}
631
+
632
+ @g = external global i64
633
+
634
+ ; PR45539 - https://bugs.llvm.org/show_bug.cgi?id=45539
635
+
636
+ define i64 @infinite_loop_constant_expression_abs (i64 %arg ) {
637
+ ; CHECK-LABEL: @infinite_loop_constant_expression_abs(
638
+ ; CHECK-NEXT: [[T:%.*]] = sub i64 ptrtoint (i64* @g to i64), [[ARG:%.*]]
639
+ ; CHECK-NEXT: [[T1:%.*]] = icmp slt i64 [[T]], 0
640
+ ; CHECK-NEXT: [[T2:%.*]] = sub nsw i64 0, [[T]]
641
+ ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T1]], i64 [[T2]], i64 [[T]]
642
+ ; CHECK-NEXT: ret i64 [[T3]]
643
+ ;
644
+ %t = sub i64 ptrtoint (i64* @g to i64 ), %arg
645
+ %t1 = icmp slt i64 %t , 0
646
+ %t2 = sub nsw i64 0 , %t
647
+ %t3 = select i1 %t1 , i64 %t2 , i64 %t
648
+ ret i64 %t3
649
+ }
You can’t perform that action at this time.
0 commit comments