Skip to content

Commit

Permalink
[InstSimplify] Add basic fold for @llvm.cheri.cap.flags.set
Browse files Browse the repository at this point in the history
If we are setting the same value we just read we can simplify the
sequence to just the original argument.
  • Loading branch information
arichardson committed May 15, 2023
1 parent 0cfb6ae commit 60c2768
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6061,6 +6061,12 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
return Op0;
}
break;
case Intrinsic::cheri_cap_flags_set:
// flags_set(x, flags_get(x)) -> x
if (match(Op1,
m_Intrinsic<Intrinsic::cheri_cap_flags_get>(m_Specific(Op0))))
return Op0;
break;
case Intrinsic::cheri_cap_offset_set:
case Intrinsic::cheri_cap_address_set: {
Value *Base = getBasePtrIgnoringCapabilityAddressManipulation(Op0, Q.DL);
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/Transforms/InstSimplify/cheri-intrinsics-get-set.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ declare i8 addrspace(200)* @llvm.cheri.cap.INTRINSIC.set.i64(i8 addrspace(200)*,


;; This is a no-op and should be folded to ret %arg
;; NB: The exception here is @llvm.cheri.cap.high.set since it is tag-clearing
;; and therefore could only be used on known-untagged values.
define i8 addrspace(200)* @fold_set_of_get(i8 addrspace(200)* %arg) nounwind {
; ADDRESS-LABEL: define {{[^@]+}}@fold_set_of_get
; ADDRESS-SAME: (i8 addrspace(200)* [[ARG:%.*]]) addrspace(200) #[[ATTR0:[0-9]+]] {
; ADDRESS-NEXT: ret i8 addrspace(200)* [[ARG]]
;
; FLAGS-LABEL: define {{[^@]+}}@fold_set_of_get
; FLAGS-SAME: (i8 addrspace(200)* [[ARG:%.*]]) addrspace(200) #[[ATTR0:[0-9]+]] {
; FLAGS-NEXT: [[VALUE:%.*]] = tail call i64 @llvm.cheri.cap.flags.get.i64(i8 addrspace(200)* [[ARG]])
; FLAGS-NEXT: [[RET:%.*]] = tail call i8 addrspace(200)* @llvm.cheri.cap.flags.set.i64(i8 addrspace(200)* [[ARG]], i64 [[VALUE]])
; FLAGS-NEXT: ret i8 addrspace(200)* [[RET]]
; FLAGS-NEXT: ret i8 addrspace(200)* [[ARG]]
;
; HIGH-LABEL: define {{[^@]+}}@fold_set_of_get
; HIGH-SAME: (i8 addrspace(200)* [[ARG:%.*]]) addrspace(200) #[[ATTR0:[0-9]+]] {
Expand Down

0 comments on commit 60c2768

Please sign in to comment.