[llvm] [InstCombine] Remove transformation on call instruction where return value need void to non-void conversion (PR #98536)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 01:21:30 PDT 2024


================
@@ -0,0 +1,49 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: llvm-as %s -o %t.bc
+; RUN: opt --passes=instcombine %t.bc -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-none-linux-android21"
+
+define dso_local void @foo() {
+entry:
+  ret void
+}
+
+define dso_local i32 @bar() {
+; CHECK-LABEL: define dso_local i32 @bar() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[_RC_:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[_RC_]], align 4
+; CHECK-NEXT:    [[CMP_NOT:%.*]] = icmp eq i32 [[TMP0]], 0
+; CHECK-NEXT:    br i1 [[CMP_NOT]], label %[[IF_THEN:.*]], label %[[IF_END:.*]]
+; CHECK:       [[IF_THEN]]:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @foo()
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
+; CHECK-NEXT:    br i1 [[CMP]], label %[[IF_END]], label %[[CLEANUP:.*]]
+; CHECK:       [[IF_END]]:
+; CHECK-NEXT:    store i32 0, ptr [[_RC_]], align 4
+; CHECK-NEXT:    br label %[[CLEANUP]]
+; CHECK:       [[CLEANUP]]:
+; CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[_RC_]], align 4
+; CHECK-NEXT:    ret i32 [[TMP1]]
+;
+entry:
+  %_rc_ = alloca i32, align 4
----------------
nikic wrote:

This test is more complicated than it needs to be. You shouldn't need much more here than a call + return.

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


More information about the llvm-commits mailing list