[llvm-bugs] [Bug 45084] New: LLVM misses conversion of load of select between pointers-to-constants into select between constants

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 2 17:50:29 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=45084

            Bug ID: 45084
           Summary: LLVM misses conversion of load of select between
                    pointers-to-constants into select between constants
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org

Similar bug in GCC (including motivation):
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94006

Testcase:

struct f { int t; };

static const struct f g0 = {0};
static const struct f g1 = {-1};

struct f f1(int a, int b) {
  return a == b ? g0 : g1;
}


IR:

%struct.f = type { i32 }

@_ZL2g0 = internal unnamed_addr constant %struct.f zeroinitializer, align 4
@_ZL2g1 = internal unnamed_addr constant %struct.f { i32 -1 }, align 4

define dso_local i32 @_Z2f1ii(i32 %0, i32 %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, %1
  %4 = select i1 %3, %struct.f* @_ZL2g0, %struct.f* @_ZL2g1
  %5 = getelementptr inbounds %struct.f, %struct.f* %4, i64 0, i32 0
  %6 = load i32, i32* %5, align 4, !tbaa.struct !2
  ret i32 %6
}

LLVM doesn't appear to notice this can be simplified to:

%struct.f = type { i32 }

@_ZL2g0 = internal unnamed_addr constant %struct.f zeroinitializer, align 4
@_ZL2g1 = internal unnamed_addr constant %struct.f { i32 -1 }, align 4

define dso_local i32 @_Z2f1ii(i32 %0, i32 %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, %1
  %4 = select i1 %3, i32 0, i32 -1
  ret i32 %4
}

(and then to

%struct.f = type { i32 }

@_ZL2g0 = internal unnamed_addr constant %struct.f zeroinitializer, align 4
@_ZL2g1 = internal unnamed_addr constant %struct.f { i32 -1 }, align 4

define dso_local i32 @_Z2f1ii(i32 %0, i32 %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, %1
  %4 = sext i1 %3 to i32
  ret i32 %4
}

or similar).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200303/4c42bd5e/attachment-0001.html>


More information about the llvm-bugs mailing list