Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[InstCombine] Drop poison generating flags on Or in simplifyAssocCastAssoc. #74763

Closed
wants to merge 2 commits into from

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Dec 7, 2023

Fixes #74739.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 7, 2023

@llvm/pr-subscribers-llvm-transforms

Author: Craig Topper (topperc)

Changes

Fixes #74739.


Full diff: https://github.com/llvm/llvm-project/pull/74763.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1)
  • (modified) llvm/test/Transforms/InstCombine/or.ll (+13)
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 30e058000d2bc..f072f5cec3094 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 fd415682b67f3..8c8aab2bcba6a 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
 }
+
+; 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 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
+}

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topperc
Copy link
Collaborator Author

topperc commented Dec 7, 2023

Committed as 09a05f5

@topperc topperc closed this Dec 7, 2023
@topperc topperc deleted the pr/assoc-cast-assoc branch December 15, 2023 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong code at -O1 and above on x86_64-linux_gnu (recent regression)
3 participants