[llvm] [InstCombine] Fix miscompilation caused by #90436 (PR #91133)

via llvm-commits llvm-commits at lists.llvm.org
Sun May 5 17:49:33 PDT 2024


================
@@ -0,0 +1,82 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+define i1 @test_eq1(i32 %x, i16 %y) {
+; CHECK-LABEL: define i1 @test_eq1(
+; CHECK-SAME: i32 [[X:%.*]], i16 [[Y:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = sext i16 [[Y]] to i32
+; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP1]], [[X]]
+; CHECK-NEXT:    ret i1 [[COND]]
+;
+  %conv1 = trunc nsw i32 %x to i8
+  %conv2 = trunc nsw i16 %y to i8
+  %cond = icmp eq i8 %conv1, %conv2
+  ret i1 %cond
+}
+
+; FIXME: It is weird that we generate truncs for test_eq2, but not for test_eq1.
----------------
goldsteinn wrote:

I think `nsw/nuw` makes `trunc` hypothetically equally easy to work with as `sext`/`zext`, but since we already have good support for ext seems straightforward to stick with what we got.

https://github.com/llvm/llvm-project/pull/91133


More information about the llvm-commits mailing list