Skip to content

Commit 616ca00

Browse files
committed
[InstCombine] Clean up bitwise folds without one-use check
1 parent 9110310 commit 616ca00

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,22 +3565,6 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
35653565
if (match(Op1, m_Xor(m_Specific(B), m_Specific(A))))
35663566
return BinaryOperator::CreateOr(Op1, C);
35673567

3568-
// ((A & B) ^ C) | B -> C | B
3569-
if (match(Op0, m_c_Xor(m_c_And(m_Value(A), m_Specific(Op1)), m_Value(C))))
3570-
return BinaryOperator::CreateOr(C, Op1);
3571-
3572-
// B | ((A & B) ^ C) -> B | C
3573-
if (match(Op1, m_c_Xor(m_c_And(m_Value(A), m_Specific(Op0)), m_Value(C))))
3574-
return BinaryOperator::CreateOr(Op0, C);
3575-
3576-
// ((B | C) & A) | B -> B | (A & C)
3577-
if (match(Op0, m_c_And(m_c_Or(m_Specific(Op1), m_Value(C)), m_Value(A))))
3578-
return BinaryOperator::CreateOr(Op1, Builder.CreateAnd(A, C));
3579-
3580-
// B | ((B | C) & A) -> B | (A & C)
3581-
if (match(Op1, m_c_And(m_c_Or(m_Specific(Op0), m_Value(C)), m_Value(A))))
3582-
return BinaryOperator::CreateOr(Op0, Builder.CreateAnd(A, C));
3583-
35843568
if (Instruction *DeMorgan = matchDeMorgansLaws(I, *this))
35853569
return DeMorgan;
35863570

llvm/test/Transforms/InstCombine/add.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ define i8 @add_xor_and_var_extra_use(i8 noundef %x, i8 noundef %y) {
18081808
; CHECK-NEXT: call void @use(i8 [[AND]])
18091809
; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[AND]], [[Y]]
18101810
; CHECK-NEXT: call void @use(i8 [[XOR]])
1811-
; CHECK-NEXT: [[ADD:%.*]] = or i8 [[Y]], [[X]]
1811+
; CHECK-NEXT: [[ADD:%.*]] = or disjoint i8 [[XOR]], [[X]]
18121812
; CHECK-NEXT: ret i8 [[ADD]]
18131813
;
18141814
%and = and i8 %x, %y

llvm/test/Transforms/InstCombine/or.ll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ define i32 @test40d(i32 %a, i32 %b) {
743743

744744
define i32 @test45(i32 %x, i32 %y, i32 %z) {
745745
; CHECK-LABEL: @test45(
746-
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Z:%.*]]
746+
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[Z:%.*]], [[X:%.*]]
747747
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[TMP1]], [[Y:%.*]]
748748
; CHECK-NEXT: ret i32 [[OR1]]
749749
;
@@ -757,7 +757,7 @@ define i32 @test45_uses1(i32 %x, i32 %y, i32 %z) {
757757
; CHECK-LABEL: @test45_uses1(
758758
; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], [[Z:%.*]]
759759
; CHECK-NEXT: call void @use(i32 [[OR]])
760-
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Z]]
760+
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[Z]], [[X:%.*]]
761761
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[TMP1]], [[Y]]
762762
; CHECK-NEXT: ret i32 [[OR1]]
763763
;
@@ -773,8 +773,7 @@ define i32 @test45_uses2(i32 %x, i32 %y, i32 %z) {
773773
; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], [[Z:%.*]]
774774
; CHECK-NEXT: [[AND:%.*]] = and i32 [[OR]], [[X:%.*]]
775775
; CHECK-NEXT: call void @use(i32 [[AND]])
776-
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X]], [[Z]]
777-
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[TMP1]], [[Y]]
776+
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[AND]], [[Y]]
778777
; CHECK-NEXT: ret i32 [[OR1]]
779778
;
780779
%or = or i32 %y, %z
@@ -787,7 +786,7 @@ define i32 @test45_uses2(i32 %x, i32 %y, i32 %z) {
787786
define i32 @test45_commuted1(i32 %x, i32 %y, i32 %z) {
788787
; CHECK-LABEL: @test45_commuted1(
789788
; CHECK-NEXT: [[YY:%.*]] = mul i32 [[Y:%.*]], [[Y]]
790-
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Z:%.*]]
789+
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[Z:%.*]], [[X:%.*]]
791790
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[YY]], [[TMP1]]
792791
; CHECK-NEXT: ret i32 [[OR1]]
793792
;
@@ -803,7 +802,7 @@ define i32 @test45_commuted2(i32 %x, i32 %y, i32 %z) {
803802
; CHECK-NEXT: [[YY:%.*]] = mul i32 [[Y:%.*]], [[Y]]
804803
; CHECK-NEXT: [[XX:%.*]] = mul i32 [[X:%.*]], [[X]]
805804
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[XX]], [[Z:%.*]]
806-
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[YY]], [[TMP1]]
805+
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[TMP1]], [[YY]]
807806
; CHECK-NEXT: ret i32 [[OR1]]
808807
;
809808
%yy = mul i32 %y, %y ; thwart complexity-based ordering
@@ -819,7 +818,7 @@ define i32 @test45_commuted3(i32 %x, i32 %y, i32 %z) {
819818
; CHECK-NEXT: [[YY:%.*]] = mul i32 [[Y:%.*]], [[Y]]
820819
; CHECK-NEXT: [[ZZ:%.*]] = mul i32 [[Z:%.*]], [[Z]]
821820
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[ZZ]], [[X:%.*]]
822-
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[YY]], [[TMP1]]
821+
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[TMP1]], [[YY]]
823822
; CHECK-NEXT: ret i32 [[OR1]]
824823
;
825824
%yy = mul i32 %y, %y ; thwart complexity-based ordering
@@ -1963,7 +1962,7 @@ define i32 @or_xor_and_uses2(i32 %x, i32 %y, i32 %z) {
19631962
; CHECK-NEXT: [[AND:%.*]] = and i32 [[Y:%.*]], [[Z:%.*]]
19641963
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND]], [[X:%.*]]
19651964
; CHECK-NEXT: call void @use(i32 [[XOR]])
1966-
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[X]], [[Y]]
1965+
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[XOR]], [[Y]]
19671966
; CHECK-NEXT: ret i32 [[OR1]]
19681967
;
19691968
%and = and i32 %y, %z

0 commit comments

Comments
 (0)