[llvm] [InstCombine] Drop poison generating flags on Or in simplifyAssocCastAssoc. (PR #74763)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 13:06:41 PST 2023


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/74763

Fixes #74739.

>From 1b25679199f8f6ccf112fed9aaafce397754aa50 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 7 Dec 2023 13:02:47 -0800
Subject: [PATCH 1/2] [InstCombine] Add test case for #74739. NFC

---
 llvm/test/Transforms/InstCombine/or.ll | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index fd415682b67f32..3dd6bb440575ff 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -1608,3 +1608,16 @@ define i8 @drop_disjoint(i8 %x) {
   %b = or disjoint i8 %a, 1
   ret i8 %b
 }
+
+; FIXME: We should drop disjoint here.
+define i32 @assoc_cast_assoc_disjoint(i16 %x) {
+; CHECK-LABEL: @assoc_cast_assoc_disjoint(
+; CHECK-NEXT:    [[B:%.*]] = zext i16 [[X:%.*]] to i32
+; CHECK-NEXT:    [[C:%.*]] = or disjoint i32 [[B]], 65537
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %a = or i16 %x, 1
+  %b = zext i16 %a to i32
+  %c = or disjoint i32 %b, 65536
+  ret i32 %c
+}

>From 62a4ab311d6ecba98b947c44267f5a57d2b57ce5 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 7 Dec 2023 13:03:53 -0800
Subject: [PATCH 2/2] [InstCombine] Drop poison generating flags on Or in
 simplifyAssocCastAssoc.

Fixes #74739.
---
 llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 1 +
 llvm/test/Transforms/InstCombine/or.ll                   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 30e058000d2bc9..f072f5cec3094a 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -356,6 +356,7 @@ static bool simplifyAssocCastAssoc(BinaryOperator *BinOp1,
 
   IC.replaceOperand(*Cast, 0, BinOp2->getOperand(0));
   IC.replaceOperand(*BinOp1, 1, FoldedC);
+  BinOp1->dropPoisonGeneratingFlags();
   Cast->dropPoisonGeneratingFlags();
   return true;
 }
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index 3dd6bb440575ff..8c8aab2bcba6a8 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -1609,11 +1609,11 @@ define i8 @drop_disjoint(i8 %x) {
   ret i8 %b
 }
 
-; FIXME: We should drop disjoint here.
+; Make sure we drop disjoint when combining the Ors.
 define i32 @assoc_cast_assoc_disjoint(i16 %x) {
 ; CHECK-LABEL: @assoc_cast_assoc_disjoint(
 ; CHECK-NEXT:    [[B:%.*]] = zext i16 [[X:%.*]] to i32
-; CHECK-NEXT:    [[C:%.*]] = or disjoint i32 [[B]], 65537
+; CHECK-NEXT:    [[C:%.*]] = or i32 [[B]], 65537
 ; CHECK-NEXT:    ret i32 [[C]]
 ;
   %a = or i16 %x, 1



More information about the llvm-commits mailing list