From ad76c682c7954ff06575cb9d7f19047a96b68f7c Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 23 Oct 2018 14:43:31 +0000 Subject: [PATCH] [InstCombine] swap select profile metadata when swapping select ops llvm-svn: 345034 --- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 1 + llvm/test/Transforms/InstCombine/select_meta.ll | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 3d346df..c15999d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1993,6 +1993,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { SI.setOperand(0, BinaryOperator::getNotArgument(CondVal)); SI.setOperand(1, FalseVal); SI.setOperand(2, TrueVal); + SI.swapProfMetadata(); return &SI; } diff --git a/llvm/test/Transforms/InstCombine/select_meta.ll b/llvm/test/Transforms/InstCombine/select_meta.ll index 250a33b..c9e277f 100644 --- a/llvm/test/Transforms/InstCombine/select_meta.ll +++ b/llvm/test/Transforms/InstCombine/select_meta.ll @@ -298,11 +298,11 @@ define i32 @umax2(i32 %x) { ret i32 %sel } -; FIXME: The condition is inverted, and the select ops are swapped. The metadata should be swapped. +; The condition is inverted, and the select ops are swapped. The metadata should be swapped. define i32 @not_cond(i1 %c, i32 %tv, i32 %fv) { ; CHECK-LABEL: @not_cond( -; CHECK-NEXT: [[R:%.*]] = select i1 [[C:%.*]], i32 [[FV:%.*]], i32 [[TV:%.*]], !prof ![[$MD1]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[C:%.*]], i32 [[FV:%.*]], i32 [[TV:%.*]], !prof ![[$MD3]] ; CHECK-NEXT: ret i32 [[R]] ; %notc = xor i1 %c, true @@ -310,11 +310,11 @@ define i32 @not_cond(i1 %c, i32 %tv, i32 %fv) { ret i32 %r } -; FIXME: The condition is inverted, and the select ops are swapped. The metadata should be swapped. +; The condition is inverted, and the select ops are swapped. The metadata should be swapped. define <2 x i32> @not_cond_vec(<2 x i1> %c, <2 x i32> %tv, <2 x i32> %fv) { ; CHECK-LABEL: @not_cond_vec( -; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i32> [[FV:%.*]], <2 x i32> [[TV:%.*]], !prof ![[$MD1]] +; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i32> [[FV:%.*]], <2 x i32> [[TV:%.*]], !prof ![[$MD3]] ; CHECK-NEXT: ret <2 x i32> [[R]] ; %notc = xor <2 x i1> %c, @@ -323,7 +323,7 @@ define <2 x i32> @not_cond_vec(<2 x i1> %c, <2 x i32> %tv, <2 x i32> %fv) { } ; FIXME: Should match vector 'not' with undef element. After that... -; FIXME: The condition is inverted, and the select ops are swapped. The metadata should be swapped. +; The condition is inverted, and the select ops are swapped. The metadata should be swapped. define <2 x i32> @not_cond_vec_undef(<2 x i1> %c, <2 x i32> %tv, <2 x i32> %fv) { ; CHECK-LABEL: @not_cond_vec_undef( -- 2.7.4