Files
clang-p2996/llvm/test/Transforms/PhaseOrdering/X86/pr48844-br-to-switch-vectorization.ll
Nikita Popov 90ba33099c [InstCombine] Canonicalize constant GEPs to i8 source element type (#68882)
This patch canonicalizes getelementptr instructions with constant
indices to use the `i8` source element type. This makes it easier for
optimizations to recognize that two GEPs are identical, because they
don't need to see past many different ways to express the same offset.

This is a first step towards
https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699.
This is limited to constant GEPs only for now, as they have a clear
canonical form, while we're not yet sure how exactly to deal with
variable indices.

The test llvm/test/Transforms/PhaseOrdering/switch_with_geps.ll gives
two representative examples of the kind of optimization improvement we
expect from this change. In the first test SimplifyCFG can now realize
that all switch branches are actually the same. In the second test it
can convert it into simple arithmetic. These are representative of
common optimization failures we see in Rust.

Fixes https://github.com/llvm/llvm-project/issues/69841.
2024-01-24 15:25:29 +01:00

58 lines
1.8 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -O2 -mattr=avx < %s | FileCheck %s
; RUN: opt -S -passes="default<O2>" -mattr=avx < %s | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; FIXME: The br -> switch conversion blocks vectorization.
define dso_local void @test(ptr %start, ptr %end) #0 {
; CHECK-LABEL: @test(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[I11_NOT1:%.*]] = icmp eq ptr [[START:%.*]], [[END:%.*]]
; CHECK-NEXT: br i1 [[I11_NOT1]], label [[EXIT:%.*]], label [[BB12:%.*]]
; CHECK: bb12:
; CHECK-NEXT: [[PTR2:%.*]] = phi ptr [ [[PTR_NEXT:%.*]], [[LATCH:%.*]] ], [ [[START]], [[ENTRY:%.*]] ]
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[PTR2]], align 4
; CHECK-NEXT: switch i32 [[VAL]], label [[LATCH]] [
; CHECK-NEXT: i32 -12, label [[STORE:%.*]]
; CHECK-NEXT: i32 13, label [[STORE]]
; CHECK-NEXT: ]
; CHECK: store:
; CHECK-NEXT: store i32 42, ptr [[PTR2]], align 4
; CHECK-NEXT: br label [[LATCH]]
; CHECK: latch:
; CHECK-NEXT: [[PTR_NEXT]] = getelementptr inbounds i8, ptr [[PTR2]], i64 4
; CHECK-NEXT: [[I11_NOT:%.*]] = icmp eq ptr [[PTR_NEXT]], [[END]]
; CHECK-NEXT: br i1 [[I11_NOT]], label [[EXIT]], label [[BB12]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
br label %header
header:
%ptr = phi ptr [ %start, %entry ], [ %ptr.next, %latch ]
%i11 = icmp ne ptr %ptr, %end
br i1 %i11, label %bb12, label %exit
bb12:
%val = load i32, ptr %ptr, align 4
%c1 = icmp eq i32 %val, 13
%c2 = icmp eq i32 %val, -12
%c3 = or i1 %c1, %c2
br i1 %c3, label %store, label %latch
store:
store i32 42, ptr %ptr, align 4
br label %latch
latch:
%ptr.next = getelementptr inbounds i32, ptr %ptr, i32 1
br label %header
exit:
ret void
}